我希望在保存操作的回调中以编程方式打开一个新选项卡。和http://jsfiddle.net/5Lwwmbq8/1/没什么区别
var atag = document.createElement('a');
atag.setAttribute('href', 'https://yahoo.com');
atag.setAttribute('target', '_blank');
atag.setAttribute('id','clickdamnit');
$('#onlydiv').append(atag);
setTimeout(function() {
atag.click();
}, 3000);如果我不把它放在回调中,一切都很好。但是在回调的范围内,它会被弹出的阻止程序阻止。有办法绕道吗?
我尝试用window.open替换锚标记--结果是一样的。
发布于 2015-01-12 06:58:41
我可以通过提供一个中间页面(比如'/sameDomainDummySpinnerPage'),然后在回调中重定向,从而破解自己的方式。
$('#linktest').click(function(){
var childWindow = window.open('/sameDomainDummySpinnerPage');
setTimeout(function() {
childWindow.location.replace('http://yahoo.com');
}, 3000);
});另一种方法是将“target”属性设置为唯一的字符串。在回调中,相同目标上的window.open会影响先前引入的选项卡。但这会导致用户体验的恶化。用户可以使用选项卡,您的脚本打开,以冲浪网络。在重新运行时,您的脚本将: 1.覆盖选项卡的现有window.location 2.可能不允许.focus();导致用户错过其操作的响应
参考文献:blank.22 http://www.infimum.dk/HTML/JSwindows.html Bypass popup blocker on window.open when JQuery event.preventDefault() is set
https://stackoverflow.com/questions/27869944
复制相似问题