简体   繁体   中英

Opening multiple tabs, attaching methods to them and having them run on the respective tabs

I am trying to figure out what's the problem with the code below: why does it work only for the first tab opened? It throws an error on the 2nd attempt on tab being null.

for(let i = 1; i <= 3; i++) 
    setTimeout(function () {
       let tab = window.open('', '_blank');
       tab.document.write('argh'); 
    }, 1000);

Browsers don't let pages open multiple windows in response to a single user event, since that's been abused repeatedly in the history of the web. Once you've created one, if you try to create another, the browser's popup blocker is likely to prevent it. You'll need to user to click repeatedly to open the windows (or do something else entirely).

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