How to put a link to a web page in a JScript Alert dialog box?

I would like to put a link to a web page in the warning dialog so that I can give a more detailed description of how to fix the error that caused the dialog to be created.

How can I make the dialog show something like this:

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

Thanks.

+4
source share
7 answers

You can try asking them if they want to visit through window.prompt:

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

In addition, Internet Explorer supports modal dialogs, so you can try to show one of them:

 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"); 
+5
source

You can not. Warning fields do not support html. You should display the error as part of the page, it is better than JS alerts.

+9
source

If you really need to, you can override the default alert () function behavior. Not to say that you should do it.

Here is an example that uses the YUI library, but you do not need to use YUI for this:

YUI-based warning window - replace your ugly javascript warning window

+6
source

You cannot - but here are a few options:

  • window.open () - create your own dialog
  • use prompt () and ask the user to copy the URL
  • use javascript to just go to the url directly (maybe after using confirmation () to ask them)
  • include a div on your page using the [FIX IT] button and display it
  • use javascript to put the patch in the user's url on the user's clipboard (not recommended).
+6
source

Or use window.open and put the link.

+2
source

Even if you could, the alert() fields were usually modal, so any open page from them should have opened in a new window. Annoyingly!

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

This is the best you can do from javascript alert. Your alternative is to try opening a new tiny window that looks like a dialog. With IE you can open it modal.

+2
source

Source: https://habr.com/ru/post/1276649/


All Articles