如何使用JavaScript在单独的线程中打开新标签页

如何使用JavaScript在单独的线程中打开新标签页

本文介绍了如何使用JavaScript在单独的线程中打开新标签页? (铬合金)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以打开将在单独的线程中运行的新弹出标签?更具体地说,如果我创建一个新的弹出标签并在该新标签中开始调试,则包含链接的标签也会暂停javascript,直到我在新标签中单击恢复"为止.我要实现的是创建一个单独的新选项卡,以便在父选项卡继续运行时对其进行调试.我在使用Chrome浏览器时遇到此问题.请注意,这在Firefox中工作正常(尚未在其他浏览器中进行测试).

Is it possible to open a new popup tab that would run in a separate thread? To be more specific, if I create a new popup tab and start debugging in that new tab, tab which contains link will also pause javascript until I click resume in a new tab. What I want to achieve is to create a new tab that is separated so I can debug it while parent tab continues running.I have this problem using Chrome browser. Note that this works fine in Firefox (haven't tested in other browsers).

推荐答案

通常chrome强制新窗口在相同的进程ID上运行.但是,有些技术可以使网站打开新窗口而不会强制其进入同一过程:

Usually chrome forces new window to run on the same Process ID.But, there are techniques which allows sites to open a new window without forcing it into the same process:

使用指向其他网站的链接,该网站以新窗口为目标,而无需传递引荐来源信息.

Use a link to a different web site that targets a new window without passing on referrer information.

<a href="http://differentsite.com" target="_blank" rel="noreferrer">Open in new tab and new process</a>

如果您希望新标签在新过程中打开,同时仍传递引荐来源信息,则可以在JavaScript中使用以下步骤:

If you want the new tab to open in a new process while still passing on referrer information, you can use the following steps in JavaScript:

  • 以about:blank为目标打开新标签.
  • 将新打开的标签页的opener变量设置为null,以使其无法访问原始页面.
  • 从about:blank重定向到与原始页面不同的网站.

例如:

var w = window.open();
    w.opener = null;
    w.document.location = "http://differentsite.com/index.html";

从技术上讲,原始网站仍然可以通过w访问新网站,但他们将.opener = null视为中立窗口的线索.

Technically the original website still has access to the new one through w, but they treat .opener=null as a clue to neuter the window.

来源: https://bugzilla.mozilla.org/show_bug.cgi?id= 666746

这篇关于如何使用JavaScript在单独的线程中打开新标签页? (铬合金)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 15:00