Solved

Detect before/when the browser leaving to another webpage

Posted on 2003-12-02
7
685 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 SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
github account with ecipse 1 48
Java Options in Zimbra Server 2 54
Java SE 8u111  Lot of stuff broke 11 69
why cannot we forward request once the response is committed 2 42
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

809 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