简体   繁体   English

如何在“ JScript警报”对话框中放置指向网页的链接?

[英]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 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. 谢谢。

You can't. 你不能 Alert boxes don't support html. 警报框不支持html。 You should display the error as part of the page, it's nicer than JS alerts anyway. 您应该在页面的一部分上显示错误,无论如何它比JS警报要好。

If you really wanted to, you could override the default behavior of the alert() function. 如果确实需要,可以覆盖alert()函数的默认行为。 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库的示例,但您不必使用YUI即可:

YUI-based alert box - replace your ugly JavaScript alert box 基于YUI的警报框-替换您难看的JavaScript警报框

You can't - but here are some options: 您不能-但是这里有一些选择:

  • window.open() - make your own dialog window.open() -创建自己的对话框
  • Use prompt() and instruct the user to copy the url 使用prompt()并指导用户复制URL
  • Use JavaScript to just navigate them to the url directly (maybe after using confirm() to ask them) 使用JavaScript将它们直接导航到url(也许在使用confirm()询问之后)
  • Include a div on your page with a [FIX IT] button and unhide it 使用[FIX IT]按钮在页面上添加一个div ,然后取消隐藏
  • Use JavaScript to put a fix it URL into the user's clipboard (not recommended) 使用JavaScript将Fix it URL放入用户剪贴板(不推荐)

You could try asking them if they wish to visit via window.prompt: 您可以尝试询问他们是否希望通过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: 另外,Internet Explorer支持模式对话框,因此您可以尝试显示以下对话框之一:

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");

或者使用window.open并将链接放在此处

Even if you could, alert() boxes are generally modal - so any page opened from one would have to open in a new window. 即使您可以, alert()框通常也是模态的-因此从其中打开的任何页面都必须在新窗口中打开。 Annoying! 烦人!

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() . 那是您可以通过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. 使用IE,您可以打开模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM