samedi 22 février 2020

onbeforeunload fires as soon as the window loads. Only happens in Safari 13

Trying to fire a function to toggle overlay on safari when opening and closing a popup window.

var newWindow = null;

function offOverlay() {
    document.getElementById("overlay").style.display = "none";
}

function onOverlay() {
    document.getElementById("overlay").style.display = "block";
}

function myFunction {
    newWindow = win.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+y+', left='+x);
    onOverlay();
    newWindow.onbeforeunload = offOverlay;
}

So with a button it'll fire myFunction() to open a popup window then it will toggle on an overlay div and add an event listener to newWindow to turn off the overlay onbeforeunload event. I tested it on chrome, firefox, safari but only safari is giving me a problem where it instantly fires of offOverlay when newWindow is loaded.

Tried using onunload but it's giving me the same problem. Not sure what could've caused this.




Aucun commentaire:

Enregistrer un commentaire