?
Solved

How to Distinguish between Refresh Button/F5 and Close Page X Button?

Posted on 2006-06-26
6
Medium Priority
?
1,128 Views
Last Modified: 2008-01-09
Hi All,
I have a page that on its onunload event i show an alert for the user.
This alert must be shown only when the user click the x button of the page to close it.
I notcied that when the page is refreshed  by the browser refresh button or pressing the F5 key...the alert is shown too...the reason that the onunload event is called here too.
Is there any way to know if the Refresh Button or F5 is the pressed and not the close x button?
Any comment will be very helpfull
Thanks in advanced.
samjav
0
Comment
Question by:samjav
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 15

Expert Comment

by:justinbillig
ID: 16983358
No, there is no way to determine if the user is closing the browser or refreshing the page. That is just the inherit behavior of the browser.
0
 
LVL 8

Expert Comment

by:kaliyugkaarjun
ID: 16984067
What u need to do is capture the window.close() event other then ONUNLOAD

You can add two lines to your script:

    function window_close() { alert("I shall not close"); }
    window.close = window_close;

Now call to window.close() will show the new alert. You can store the
original function aside, e.g.

    var backup = new Object(); backup.close = window.close;

(naturally, you do that before you reassign window.close). Now you can
perform all your verification and call the orignal function to close the
window.


U can  capture the reload/refresh event in Javascript as below
You would use the onLoad event in the body tag.
<BODY onLoad="some_function()">

Try it..
0
 

Author Comment

by:samjav
ID: 16990144
hi kaliyugkaarjun
after i put the script codes you mentioned, where shall i call it?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Accepted Solution

by:
kaliyugkaarjun earned 160 total points
ID: 16991698
0
 

Expert Comment

by:mailtovenkats
ID: 21884308
Hi,
im also facing same problem.
Could any one help me on this...
How can I distinguish the browser close condition from the refresh condition and close button
0
 

Expert Comment

by:mailtovenkats
ID: 21884384
Hi
   im also facing same problem. How can I distinguish the browser close from the refresh in page unload.

i could not able to get solution for this.
basically , when user close the browser , i would like to call one function and when page refersh that function should not be called...

Please advice...i trying this for so many days.. but no proper result

Thanks in advance..
venki
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question