lilmer Posted December 1, 2016 Share Posted December 1, 2016 Hello, I want to add a process that will trigger a show of advertisement or opening a new tab when the user close a the tab or browser. $(window).bind("beforeunload", function(e) { window.open(URL+'ads', '_blank'); return 'You are closing the browser'; }); The window.open and the return message is both not working. I tried also other possibilities but window.open is not working. Anyone knows about this? Quote Link to comment https://forums.phpfreaks.com/topic/302653-on-close-browser/ Share on other sites More sharing options...
requinix Posted December 1, 2016 Share Posted December 1, 2016 What you want to do is despicable. Are you saying the onbeforeunload works but the window.open does not? If it's not a problem with the code itself (eg, "URL" undefined or invalid) then it's likely that the browser is deliberately preventing that from happening. Quote Link to comment https://forums.phpfreaks.com/topic/302653-on-close-browser/#findComment-1539912 Share on other sites More sharing options...
Jacques1 Posted December 1, 2016 Share Posted December 1, 2016 What you want to do is despicable. I couldn't agree more. Aggressive ads are already the cancer of the Internet, but popping up a new window when I want to close the current one makes me want to punch the developer in the face. Seriously, stop it. Even if you manage to get your code past the browser's malware filter, your users will be truly annoyed and either turn their ad blocker all the way up or leave your site forever. It's just counter-productive. Quote Link to comment https://forums.phpfreaks.com/topic/302653-on-close-browser/#findComment-1539922 Share on other sites More sharing options...
Psycho Posted December 1, 2016 Share Posted December 1, 2016 I would comment on what the OP is wanting to implement. But, then I would have to ban myself for language. Quote Link to comment https://forums.phpfreaks.com/topic/302653-on-close-browser/#findComment-1539923 Share on other sites More sharing options...
lilmer Posted December 15, 2016 Author Share Posted December 15, 2016 Nope, its not a usual page ads thats keeps on triggering every time you exit a site. This is for specific user and by user level, and once you agree to terms it will not pop again. Quote Link to comment https://forums.phpfreaks.com/topic/302653-on-close-browser/#findComment-1540359 Share on other sites More sharing options...
Jacques1 Posted December 15, 2016 Share Posted December 15, 2016 It doesn't matter what kind of ad this is. It's garbage. Quote Link to comment https://forums.phpfreaks.com/topic/302653-on-close-browser/#findComment-1540371 Share on other sites More sharing options...
.josh Posted December 15, 2016 Share Posted December 15, 2016 (edited) Literally the only thing I have ever seen popup when I try to close my tab/browser or otherwise navigate from the page that I only _marginally_ consider "okay" (read: barely tolerable) is a warning about losing unsaved changes to something. Edited December 15, 2016 by .josh 1 Quote Link to comment https://forums.phpfreaks.com/topic/302653-on-close-browser/#findComment-1540411 Share on other sites More sharing options...
Stefany93 Posted December 31, 2016 Share Posted December 31, 2016 (edited) ^^ Actually I find the pop-up quite useful if I am writing something and accidentally click the close button on a tab or browser (pls don't hate me, lol) especially if there is no auto safe. As for the op, it is not possible to write to add a custom message onbeforeunload or any event that is triggered when the user wants to leave. You can add some text (on few browsers) additionally to the default message and that's it. Browsers do that for defense. Edited December 31, 2016 by Stefany93 Quote Link to comment https://forums.phpfreaks.com/topic/302653-on-close-browser/#findComment-1540917 Share on other sites More sharing options...
Stielle Posted January 6, 2017 Share Posted January 6, 2017 ^^ Actually I find the pop-up quite useful if I am writing something and accidentally click the close button on a tab or browser (pls don't hate me, lol) especially if there is no auto safe. This is acceptable if I have coded an application that a user is working in and wants to leave an area without saving. But as a 'WAIT DON'T LEAVE!' for a webpage, I make a point to not go back to that site again, report it, etc. Quote Link to comment https://forums.phpfreaks.com/topic/302653-on-close-browser/#findComment-1541105 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.