开发者

disable javascript popup on refreshing page

开发者 https://www.devze.com 2023-01-02 06:33 出处:网络
I have written code like this to throw a pop up when my website is closed. But this throws the pop up even if i refresh my page. Please help me to throw popup only when i close the browser of that web

I have written code like this to throw a pop up when my website is closed. But this throws the pop up even if i refresh my page. Please help me to throw popup only when i close the browser of that website. 开发者_高级运维(disable popup on refreshing page)

<body onunload="javascript: exitpop()">

<script type="text/javascript">
function exitpop()
{
my_window= window.open ("","mywindow1","status=1,width=600,height=400"); 
my_window.document.write('<h1>My Team</h1><p>Thank you</p><p>If you accidentally closed website click <a href="http://www.google.com">here</a> to go back to our website</p>'); 
}.


onUnLoad is called on a refresh because the browser is requesting a new page (well, the same page in the case of a refresh, but it is still a new call).

I am not sure if there is a way to check where the user is going next, but if there is you could compare it to their current url, if they are the same then the user is just refreshing and the script doesn't need to be run.

Good luck


Sadly, this is not possible. To the browser, it is essentially the same action.

However, if you just use a confirm() box, you can catch a user that is trying to leave without linking them back. If they are refreshing or if they really want to leave, hitting "OK" will allow that action to occur.

Let me know if you need this explained further.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号