Force window.open() to create new tab in chrome

后端 未结 5 1843
轻奢々
轻奢々 2020-11-30 03:32

I use window.open to populate a new window with varying content. Mostly reports and stored HTML from automated processes.

I have noticed some very inconsistent beha

5条回答
  •  粉色の甜心
    2020-11-30 03:46

    I have tried this and it worked fine in chrome. If opening a new tab is on a user action(such as a mouse click) this will work fine without any issues. But if the code is executed in another script block, you may need to enable pop-ups in chrome. Looks like this is to handle all the click-bait sites.

    let newTab = window.open('', '_blank');
    if (this.viewerTab == null) {
      console.log("opening in new tab to work, pop-ups should be enabled.");
      return;
    }
    
    ................
    
    newTab.location.href = viewerUrl;
    

提交回复
热议问题