Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2007
    Posts
    34
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Leaving Site Function

    I'm trying to build something with either javascript or php that will prompt a security message when leaving the site.

    I did some research and I found very basic ways to this but it only applied to one link. I would like to simply add a onclick to any link on any page that will tag the link as an exiting link.

    Here the basic code, this is the first default page:
    Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Link Test</title>
    
    <script type="text/javascript">
    <!--
    function Terms() {
    popup=window.open('security.php','windowName','width=500,height=300');
    if (!popup.opener) popup.opener = self;
    }
    -->
    </script>
    </head>
    
    <body>
    <a href="#" onClick="Terms()">www.google.com</a>
    </body>
    </html>
    And then here's the second page (security.php):
    Code:
    <html>
    <head>
    <script type="text/javascript">
    <!--
    function confirmation() {
    	var answer = confirm("Are you sure you want to leave?")
    	if (answer){
    		window.location = "http://www.google.com/";
                   //This location above needs to be dynamic to the link from the first page
    	}
    	else{
    		window.close();
    	}
    }
    //-->
    </script>
    </head>
    <body>
    <form>
    <input type="button" onclick="confirmation()" value="Leave?">
    </form>
    </body>
    </html>
    Time after Time

  • #2
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    I think you could just do it with onunload or something
    http://www.w3schools.com/jsref/jsref_onunload.asp

  • #3
    New Coder
    Join Date
    Nov 2007
    Posts
    34
    Thanks
    9
    Thanked 0 Times in 0 Posts
    The problem with onunload is that it triggers the event with every link and during refreshes. I would only need this prompt if the user was going to a specific outside link where we do not monitor the site because we have multiple DNS's.
    Time after Time


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •