Is there a Alternative of onbeforeunload event that can handle on close tab or existing page on a browser?

2,659 views
Skip to first unread message

Junyx Tips

unread,
Sep 13, 2018, 2:00:29 AM9/13/18
to Chromium-discuss
Hello,


Is there a Alternative of onbeforeunload event that can handle on close tab or existing page on a browser? On chromium policy they stated that on the new update of chrome they remove the onbeforeunload event

This my code which is working other browser except google chrome

<script type="text/javascript">
var areYouReallySure = false;
function areYouSure() {
    if(allowPrompt){
        if (!areYouReallySure && true) {
            areYouReallySure = true;
var hey = "me";
window.location.href = "google.com";
            return hey;
        }
    }else{
window.location.href = "google.com";
        allowPrompt = true;
    }
}

var allowPrompt = true;
window.onbeforeunload = areYouSure;
</script>

Please help... thanks!

PhistucK

unread,
Sep 13, 2018, 2:05:25 AM9/13/18
to jun.lu...@gmail.com, Chromium-discuss
beforeunload is supported in Chrome. It is ignored without a user activation (a click on the page or similar interactions), though.
My guess is that the navigation (location.href = "...") is problematic, though.
Do you know whether your return hey is even reached?
Do you see any error in the console (make sure the console is persisted across navigations, otherwise the error will be cleared)?

PhistucK


--
--
Chromium Discussion mailing list: chromium...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss

---
You received this message because you are subscribed to the Google Groups "Chromium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discu...@chromium.org.
Reply all
Reply to author
Forward
0 new messages