473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

How to "tell" my message box to pop up only when user close the browser?

4
I am trying to write a code such that when user close the browser or netvigate to other page, a message box will show up.

Expand|Select|Wrap|Line Numbers
  1.     <SCRIPT>
  2.     function closeIt()
  3.       {
  4.         event.returnValue = "Any unsaved data will be lost.";
  5.       }
  6.     </SCRIPT>
  7.  
  8. <BODY onbeforeunload="closeIt()">
but then every time something in my web postback or reload, the same message box popup. I only want this to happen when user close the browser or netvigate to other page, not when the current webpage reload. How could I solve this problem?
Jul 11 '07 #1
5 2566
nic829
4
I wrote the following code such that when user close my webpage or netvigate to other page, a message box pop up:

Expand|Select|Wrap|Line Numbers
  1. <head>    
  2. <SCRIPT>
  3.     function closeIt()
  4.       {
  5.         event.returnValue = "Any unsaved data will be lost.";
  6.       }
  7.     </SCRIPT> 
  8. </head>
  9. <BODY onBeforeUnload="closeIt()">

but in my webpage there is some dropdown list, and everytime when the selected index of dropdown list changed, there is an auto post back. so everytime when i select something from the dropdown list, the message appears even i'm not leaving the page. Is there any ways that my message box will appear only when the user close the webpage or netvigate to somewhere else?
Jul 12 '07 #2
acoder
16,027 Expert Mod 8TB
Merged threads .
Jul 12 '07 #3
iam_clint
1,208 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. window.onbeforeunload = function() {
  3. return 'By clicking ok, the data on this page will be lost.';
  4. }
  5. </script>
  6.  
Jul 12 '07 #4
For this pop up comes evey time, whether any chabges done on page, how to verify control state before showing pop up
Apr 2 '09 #5
acoder
16,027 Expert Mod 8TB
Use a variable initially set to false:
Expand|Select|Wrap|Line Numbers
  1. var anychanges = false;
then whenever a change is made, set it to true. In the function, add this:
Expand|Select|Wrap|Line Numbers
  1. .. = function() {
  2.     if (anychanges) return ...
  3. }
Apr 2 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ted Byers | last post by:
I have gotten to the point where attempting to run my application using "java -jar HotSpotImageTest.jar" no longer generates a complaint about not finding function main. It turned out that the...
9
by: Russ Perry Jr | last post by:
I'm using "ID" and "Value" in the generic sense here... Let's say one page I had a <html:select> with a collection like this: <html:options collection="items" property="key"...
8
by: Calan | last post by:
I have a server-side ASP script that dynamically creates an input form from a database table. The table contains a field name, the table where values are stored, type of input control, value for a...
15
by: Gérard Talbot | last post by:
Hello all, I'd like to know and understand the difference between, say, <img src="/ImageFilename.png" width="123" height="456" alt=""> and <img src="/ImageFilename.png" style="width:...
1
by: Daisy | last post by:
error CS0117: 'System.Collections.ArrayList' does not contain a definition for 'Item' Only one answer in Google Groups, and I'm positive I'm using it correctly...! Posts is my ArrayList. I...
18
by: jrhoads23 | last post by:
Hello, I am trying to find a way to tell if an .NET windows forms Button (System.Windows.Forms.Button) is "depressed" (pushed down). For my application, I can not use a check box control set to...
5
by: pauldepstein | last post by:
Take the code: int ival = 1024; int &refVal = ival; My text says "a reference is just another name for an object ... we can access refVal through ival ..." I understand this way of using...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
2
by: =?ISO-2022-JP?B?GyRCJD8kKxsoQg==?= | last post by:
Hi everyone, I am developing the console which has the embedded Python interactive interpreter. So, I want to judge whether current command is complete or not. Below is good example to solve...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.