Confirmation on Window Closing Issue

Javascript coding ..

Moderators: egami, macek, gesf

Post Reply
User avatar
AeroX
New php-forum User
New php-forum User
Posts: 140
Joined: Sun May 11, 2008 1:40 am
Location: London, UK
Contact:

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>
AeroX.

When posting code to be reviewed please enclose it in the [ code ] [ /code ] tags as it makes it a lot easier for people to read as it correctly formats itself on screen.

Image
    Click Here to Visit[/url]

    User avatar
    AeroX
    New php-forum User
    New php-forum User
    Posts: 140
    Joined: Sun May 11, 2008 1:40 am
    Location: London, UK
    Contact:

    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>
    AeroX.

    When posting code to be reviewed please enclose it in the [ code ] [ /code ] tags as it makes it a lot easier for people to read as it correctly formats itself on screen.

    Image
      Click Here to Visit[/url]

      Post Reply
      • Information
      • Who is online

        Users browsing this forum: No registered users and 2 guests