简体   繁体   中英

Chrome synchronizes tabs after window.open()

I got some problem when testing my web application in chrome.When I open a new tab programmatically using window.open(href), two tabs are working synchronized, it means when I stop on debugger in javascript on one of them, the second one is frozen. Is this a proper chrome behavior? Is there way to solve this problem? In firefox the same issue works fine.

This behavior is correct. Windows opened using Javascript share a Javascript interpreter with their parent — calling window.open() returns a reference to the new window, and the child can get a reference to the parent through window.opener . So long as the windows are displaying pages from the same origin, scripts running in the two windows can share data through these references, as the Window object is also the Javascript global context. For instance, if the parent window has a global variable called example , the child window can reference this variable as window.opener.example .

Since the two windows share a Javascript interpreter, it stands to reason that stopping one of them in the debugger should stop both. I'm not sure why Firefox isn't doing this — not stopping both windows involved seems like it could make debugging some scripts very difficult.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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