Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML JavaScript

Confirmation on Window Closing Issue

Javascript coding ..

Moderators: macek, egami, gesf

Re: Confirmation on Window Closing Issue

Postby AeroX » Tue Aug 05, 2008 11:15 pm

Unchecked code.

You will have to try and look up how to do the "[page you are going to does not contain myDomain then show message]" bit as i don't have enough time at the moment but it should be roughly like
Code: Select all
!contains( [new page url], myDomain )


Code: Select all
<html>
<head>
<title>Testing.</title>
<script language="JavaScript">
<!--
var myDomain = "mysite.com";
window.onbeforeunload = bunload;

function bunload(){
    if( [page you are going to does not contain myDomain then show message] )
    {
        dontleave="Are you sure you want to leave?";
        return dontleave;
    }
}
//-->
</script>
</head>
<body>
Please stay on this page!
</body>
</html>
User avatar
AeroX
New php-forum User
New php-forum User
 
Posts: 142
Joined: Sun May 11, 2008 1:40 am
Location: London, UK

Re: Confirmation on Window Closing Issue

Postby AeroX » Wed Aug 06, 2008 2:10 am

Just replace "[url the user is going to]" with a var cotaining the url of the page they are being redirected to.

Code: Select all
<html>
<head>
<title>Testing.</title>
<script language="JavaScript">
<!--
var myDomain = "mysite.com";
window.onbeforeunload = bunload;

function bunload(){
    if( [url the user is going to].match( myDomain ) == null )
    {
        dontleave="Are you sure you want to leave?";
        return dontleave;
    }
}
//-->
</script>
</head>
<body>
Please stay on this page!
</body>
</html>
User avatar
AeroX
New php-forum User
New php-forum User
 
Posts: 142
Joined: Sun May 11, 2008 1:40 am
Location: London, UK


Return to JavaScript

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.