Solved

Detect before/when the browser leaving to another webpage

Posted on 2003-12-02
7
683 Views
Last Modified: 2013-12-16
When a JApplet is loaded and the browser browse to another webpage the applet (the main JFrame) is closed without a warning.  Can a I detect that it in advance to prevent the browser from leaving the webpage or at least warn the user or so?
0
Comment
Question by:s_lavie
  • 5
  • 2
7 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 9858274
add onLoad and onUnload javascript to the webpage...

That will fire javascript when the page is loaded, and when they leave the page...

You can't stop them leving though, so what you want to do isn't possible :-(
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9858283
ie:

<body onLoad="alert( 'Hi!' )" onUnload="alert( 'Bye!' )">
0
 
LVL 2

Author Comment

by:s_lavie
ID: 9858334
Can I issue a yes/no dialog that the user can regret before the browser leaves the webpage?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 35

Expert Comment

by:TimYates
ID: 9858365
There is

onBeforeUnload

but it is only available in Internet Explorer

http://www.webreference.com/dhtml/diner/beforeunload/index.html

----------------

<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
<!--
function unloadMess(){
    mess = Leaving so soon?"
    return mess;
}

function setBunload(on){
    window.onbeforeunload = (on) ? unloadMess : null;
}

setBunload(true);
//-->
</SCRIPT>
0
 
LVL 2

Author Comment

by:s_lavie
ID: 9858772
I'm quite weak with JavaScript.  I'd appreciate if you add a sample code that includes the yes/no dialog and the canceling of moving to another webpage,
10x
0
 
LVL 35

Accepted Solution

by:
TimYates earned 50 total points
ID: 9858897
<html>
    <head>
        <title>Tim's cool test!</title>

        <SCRIPT>
        <!--
            function unloadMess()
            {
                mess = 'Leaving so soon?' ;
                return mess;
            }

            function setBunload(on)
            {
                window.onbeforeunload = (on) ? unloadMess : null;
            }

            function pageLoaded()
            {
                alert( 'Setting the beforeUnload handler (IE ONLY)' ) ;
                setBunload(true);
            }

            function pageClosed()
            {
                alert( 'Closing the page' ) ;
            }
        //-->
        </SCRIPT>

    </head>
    <body bgcolor="#FFDDFF" onload="javascript:pageLoaded()" onUnload="javascript:pageClosed()">
        <a href="http://www.google.com">Go to google</a><br/>
        <a href="http://www.experts-exchange.com">Go to experts Exchange</a><br/><br/>
        Clicking either of these (in IE) will ask if you're sure!!
    </body>
</html>
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9858906
Mmmmm.....pink ;-)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now