views:

605

answers:

7

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 can I make the dialog box show something like this:

There was an error.  Go to this page to fix it.
wwww.TheWebPageToFix.com

Thanks.

+7  A: 

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.

MattW.
+2  A: 

Or use window.open and put the link there.

Gulzar
+2  A: 

Even if you could, alert() boxes are generally modal - so any page opened from one would have to open in a new window. Annoying!

Shog9
+2  A: 
alert("There was an error. Got to this page to fix it.\nwww.TheWebPageToFix.com");

That's the best you can do from a javascript alert. Your alternative option is to try and open a new tiny window that looks like a dialog. With IE you can open it modal.

DrFloyd5
+5  A: 

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

jessegavin
+4  A: 

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)
Hafthor
Thanks. I used confirm()
Keng
+2  A: 

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");
else
   window.open("mypage.html","name","height=255,width=250,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes");
rpetrich
Code will always get you props on my questions ;o)
Keng