Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-06-26
6
Medium Priority
?
1,136 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…

604 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