Open new window after a click event not working in Safari, Chrome

冷暖自知 提交于 2019-11-28 09:15:14

Safari/Chrome have built-in pop-up blockers that stop this from working. The only javascript that is allowed to open a new window in Safari/Chrome is javascript directly attached to click handlers (and other direct user input handlers). In past versions people figured out some ways to cheat (like generating some other element -- a form or div -- and simulating user input with javascript), but newer versions are smarter about detecting this. I'd recommend re-configuring things so that you don't use a delayed pop-up -- that is the kind of thing that can generally be jarring to a user after all.

I got around this by checking the return value of window.open() for undefined. If that is true call alert() with a message for the user to to disable their popup blocker.

var myWin = window.open([args]);

if (myWin == undefined)
   alert('Please disable your popup blocker');

Another workaround
Just open a popup with ACCEPT and CANCEL options and attach the window.open
action to the ACCEPT button and it will works. It worked for me...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!