选项卡式浏览导致 Javascript 不一致?

发布于 2024-07-30 06:35:40 字数 1065 浏览 8 评论 0原文

在选项卡式浏览器(对我来说是 FF 3.5)中,我经常使用 CTRL 键单击或中键单击在新选项卡中打开链接。 当链接包含 Javascript 函数时,可以:

  • 打开一个空白的新选项卡,并在地址栏中显示 javascript:window.print() 或“what-have-you”。
  • 该函数成功执行并且打开一个空白的新选项卡。

事实是,这似乎并不是所有 Javascript 函数都会一致发生。 例如:

  1. 此页面,当按住 CTRL 键单击时,打开打印对话框并生成一个空的新选项卡。
  2. 白皮书链接位于此页面,当按住 CTRL 键单击时,仅生成一个空的新选项卡。

有问题的链接分别包含以下代码:

  1. javascript:window.print();
  2. javascript:_hbRedirect('PDF Downloads','White Paper','URL.pdf',' &c1=TITLE|US-en')

这个问题有点类似。 评价最高的答案详细介绍了基于 AJAX 的解决方案,但我找不到解释为什么某些 Javascript 函数在选项卡上的行为与其他函数不同。

In a tabbed browser (FF 3.5 in for me), I often open links in new tabs with CTRL-click or middle-click. When the link contains a Javascript function, either:

  • A blank new tab opens with javascript:window.print() or what-have-you in the address bar.
  • The function executes successfully and a blank new tab opens.

Thing is, this doesn't seem to happen consistently for all Javascript functions. For example:

  1. The "Print" button on this page, when CTRL-clicked, opens a print dialogue and generates an empty new tab.
  2. The Whitepaper links on this page, when CTRL-clicked, only generates an empty new tab.

The links in question contain the following code, respectively:

  1. javascript:window.print();
  2. javascript:_hbRedirect('PDF Downloads','White Paper','URL.pdf','&c1=TITLE|US-en')

This SO question is somewhat similar. The best-rated answer details an AJAX-based solution, but I could not find an explanation for why some Javascript functions behave differently with tabs than others.

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

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

发布评论

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

评论(2

中二柚 2024-08-06 06:35:41

发生这种情况是因为 window.print() 已默认定义,因此可以正常调用。

javascript:_hbRedirect('PDF Downloads','White Paper','URL.pdf','&c1=TITLE|US-en') 链接调用未定义的函数,因此不会发生任何情况。

That happens because window.print() is already defined by default so it is called normally.

The javascript:_hbRedirect('PDF Downloads','White Paper','URL.pdf','&c1=TITLE|US-en') link calls an undefined function so nothing happens.

无人接听 2024-08-06 06:35:41

JavaScript 不应与 XHTML 混合。 让链接的 href 属性只是您要链接到的页面或文档。 如果您想使用 a 标签做一些特殊的事情,请使用事件注册。

A la MooTools:

a.addEvent ('click', function (e) {

});

JavaScript shouldn't be mixed with XHTML. Let the href attribute of a link just be the page or the document you want to link to. If you want to do something special with an a tag, use event registering.

A la MooTools:

a.addEvent ('click', function (e) {

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