/    Sign up×
Community /Pin to ProfileBookmark

Link inside alert()?

Is it possible to display an alert message with a link to somewhere inside it?

The only other way I can think of is to create a pop-up window
with a link to where I want to go, but I won’t know if it has been blocked
or if javascript is disabled.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@ZeroKilledOct 19.2007 — alert message doesn't display other content than plain text, no image, no link, no html redering, just text. that is how the alert work. if user had disabled javascript you can neighter display an alert message.
Copy linkTweet thisAlerts:
@JMRKERauthorOct 19.2007 — Thanks 'ZeroKilled'. Saves a lot of effort.

I'll try a dynamic pop-up with link.

Purpose: I want to tell the user there is a link they can go to and allow that to happen or just cancel the pop-up window if they choose not to go to the link.
Copy linkTweet thisAlerts:
@cridleyOct 19.2007 — I'd do something like display a nice div in the middle of the browser and fade the background for best effect.
Copy linkTweet thisAlerts:
@JMRKERauthorOct 19.2007 — Thanks for the idea 'cridley'. Sounds even easier than what I had thought.

I'll get back with my attempts later.
Copy linkTweet thisAlerts:
@JMRKERauthorOct 20.2007 — For those who might be interested,

here's what I came up with from the ideas supplied: ?

Thanks to all who commented.

[code=php]
<html>
<head>
<title>Jump Menu</title>
<script type="text/javascript">

function JumpTo(site) { location.href=site; }

// JumpMenu SiteList format: Links|Names
SiteList = new Array(
'http://www.nytimes.com/2007/09/11/health/11visi.html?_r=2&th=&adxnnl=1&oref=slogin&emc=th&adxnnlx=1189528347-faFUpIcNttrreuIMHB9Cow&oref=slogin|Double Vision',
"http://www.opt.indiana.edu/riley/HomePage/Automated_Perimetry/Text_Auto_perm.html|Automated Field Analyzer",
'http://opt.pacificu.edu/ce/catalog/pupil_anomalies/index.html|Pupil Anomalies',
'http://www.opt.indiana.edu/riley/HomePage/Tanget_Screen/Text_TangetScreen.html|Tangent Screen',
'http://www.academy.org.uk/tutorials|Tutorials (several)',
'');

function SetJumpToMenu() {
var str = '';
str += '<select id="JumpToSites"';
str += ' onChange="JumpTo(this.value);document.getElementById('AddLinks').style.display='none'">';
str += '<option value="">Useful Sites</option>';
for (var i=0; i<SiteList.length-1; i++) {
site = SiteList[i].split('|');
str += '<option value="'+site[0]+'">'+site[1]+'</option>';
}
str += '</select>';
return str;
}

var User = 'username';
var Site = 'domain.edu';
function EmailUser() {
var str = '<a href="mailto:' + User+'@'+Site;
str += '?Subject=Useful links&Body=Send the site URL';
str += ' and Description" />?</a>';
return str;
}
function ToggleInfo(IDinfo) {
var obj = document.getElementById(IDinfo);
if (obj.style.display == 'none') { obj.style.display = ''; }
else { obj.style.display = 'none'; }
}
</script>

</head>
<body>

<script type="text/javascript">
document.write(SetJumpToMenu());
document.write('<a href="#" onClick="ToggleInfo('AddLinks')">Add?</a>');
document.write('<div id="AddLinks"');
document.write(' style="display:none;background-color:yellow;width:200">');
var str='Want to add more links here?<p />';
str += 'Send an email with site URL<br /> and a description to:<br />';
str += '<a href="mailto:' + User+'@'+Site;
str += '?Subject=Useful links&Body=Send the site URL';
str += ' and Description" />'+User+'@'+Site+'</a>';
document.write(str);
document.write(EmailUser());
document.write('</div>');
</script>
<p />Additional page information continues:<br /><hr />
</body>
</html>
[/code]


Would welcome any thoughts on script improvements.

Next feature I would like to add would be to pass a parameter

in the function SetJumpToMenu('SiteList') to allow different 'SiteList' array names

to be passed for multiple select box displays on the page.
×

Success!

Help @JMRKER spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...