Skip to content Skip to sidebar Skip to footer

How Do I Put A Link To A Webpage In A Jscript Alert Dialog Box?

I would like to put a link to a webpage in an alert dialog box so that I can give a more detailed description of how to fix the error that makes the dialog box get created. How c

Solution 1:

You can't. Alert boxes don't support html. You should display the error as part of the page, it's nicer than JS alerts anyway.

Solution 2:

You can't - but here are some options:

  • window.open() - make your own dialog
  • Use prompt() and instruct the user to copy the url
  • Use JavaScript to just navigate them to the url directly (maybe after using confirm() to ask them)
  • Include a div on your page with a [FIX IT] button and unhide it
  • Use JavaScript to put a fix it URL into the user's clipboard (not recommended)

Solution 3:

If you really wanted to, you could override the default behavior of the alert() function. Not saying you should do this.

Here's an example that uses the YUI library, but you don't have to use YUI to do it:

YUI-based alert box - replace your ugly JavaScript alert box

Solution 4:

You could try asking them if they wish to visit via window.prompt:

if(window.prompt('Do you wish to visit the following website?','http://www.google.ca'))
  location.href='http://www.google.ca/';

Also, Internet Explorer supports modal dialogs so you could try showing one of those:

if (window.showModalDialog)
   window.showModalDialog("mypage.html","popup","dialogWidth:255px;dialogHeight:250px");
elsewindow.open("mypage.html","name","height=255,width=250,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes");

Solution 5:

Or use window.open and put the link there.

Post a Comment for "How Do I Put A Link To A Webpage In A Jscript Alert Dialog Box?"