javascript - Beforeunload is not working to redirect user to another page, how can I redirect user to another page/url when he attempts to close a window/tab? -
my following code isn't working redirect user page:
$(window).on('beforeunload',function(){ window.location.href="http://www.google.com; }) ; i want user redirected page when attempts close tab. what's alternative , appropriate way achieve this?
*don't it*
but possible user's permission; can achieve (took me while find website happy in frame)
window.onbeforeunload = function () { window.settimeout(function () { // escape function context window.location = 'http://bbc.co.uk'; }, 0); window.onbeforeunload = null; // necessary prevent infinite loop // kills browser return 'press "stay on page" go bbc website!'; // pressing leave still leave, may fired first anyway }
Comments
Post a Comment