简体   繁体   中英

Opening an url in a new tab instead of a popup (after click)

The user clicks a context-menu to create a new item, the item is saved async and a url is opened in a new tab when save is done. Thats what I want but Chrome is opening the url in a popup instead of a new tab. When opening the window outside the saveasync-then-handler it works fine (the commented code), but not inside. Anything I can do get the same behaviour inside the handler? I have tried using open.bind(this) but that didn't help...

var open = function() {
  var win = window.open('/page', '_blank');
  win.focus();
};

client.SaveAsync().then(open); // This doesn't work, opens in a popup window

open(); // This works, opens in a new tab

Have the same issue, it's browser protection. Managed to solve it with a workaround:

var win = window.open('/page', '_blank');
client.SaveAsync().then(function() {
    win.open('/page', '_self');
});

The trick is that it works when it's not inside an async request like a response of a http request, so we open it before the request and redirect it after we get the response.

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