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

后端 未结 3 1518
广开言路
广开言路 2020-12-09 19:52

I\'m trying to open a new window like so:

$(\'#wrapper\').click(function() {
    window.setTimeout(function() {
        //alert(\'hi\');
        window.open(         


        
相关标签:
3条回答
  • 2020-12-09 20:13

    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.

    0 讨论(0)
  • 2020-12-09 20:22

    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');
    
    0 讨论(0)
  • 2020-12-09 20:26

    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...

    0 讨论(0)
提交回复
热议问题