Solved

Detect before/when the browser leaving to another webpage

Posted on 2003-12-02
7
684 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this short web based tutorial, I wanted to show users how they can still use the powers of FrontPage in conjunction with Expression Web 3.  Even though Microsoft eliminated the use of Web components, we can still use them with FrontPage and edit …
This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

911 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

22 Experts available now in Live!

Get 1:1 Help Now