如何将网页链接放入 JScript 警报对话框中?

发布于 2024-07-04 07:26:51 字数 191 浏览 5 评论 0原文

我想在警报对话框中放置一个网页链接,以便我可以更详细地描述如何修复导致创建对话框的错误。

我怎样才能让对话框显示这样的内容:

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

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

如何视而不见 2024-07-11 07:26:51

您可以尝试询问他们是否希望通过 window.prompt 进行访问:

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

此外,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");

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");
债姬 2024-07-11 07:26:51

如果您确实愿意,您可以覆盖 alert() 函数的默认行为。 并不是说您应该这样做。

下面是一个使用 YUI 库的示例,但您不必使用 YUI 来执行此操作:

基于 YUI 的警报框 - 替换丑陋的 JavaScript 警报框

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

℉絮湮 2024-07-11 07:26:51

你不能 - 但这里有一些选项:

  • window.open() - 创建自己的对话框
  • 使用 prompt() 并指示用户复制 url
  • 使用 JavaScript 来只需直接将他们导航到网址(可能在使用 confirm() 询问他们之后)
  • 在页面上包含一个带有 [FIX IT] 按钮的 div 并取消隐藏
  • 使用 JavaScript将修复 URL 放入用户的剪贴板(不推荐)

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)
卖梦商人 2024-07-11 07:26:51

你不能。 警报框不支持 html。 您应该将错误显示为页面的一部分,无论如何它比 JS 警报更好。

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.

你怎么敢 2024-07-11 07:26:51
alert("There was an error. Got to this page to fix it.\nwww.TheWebPageToFix.com");

这是 JavaScript alert() 所能做的最好的事情。 您的替代选择是尝试打开一个看起来像对话框的新小窗口。 使用 IE 可以打开它模式。

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.

挖鼻大婶 2024-07-11 07:26:51

即使可以,alert() 框通常是模态的 - 因此从其中打开的任何页面都必须在新窗口中打开。 恼人的!

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

伪装你 2024-07-11 07:26:51

或者使用 window.open 并将链接放在那里

Or use window.open and put the link there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文