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 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2011
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Code that automatically redirects a visitor after they click anywhere on the page?

    I'm looking for code which does the following:

    When a visitor visits my website and clicks anywhere on the page, (regardless of where the mouse clicks) it will automatically redirect him to another site.

    I think an event listener might be a solution, but I'm not sure.

    Thanks a lot for any help on this

    If possible, I would like there to be a 2 second time delay before it does the redirection.
    Last edited by tridentspk; 09-05-2011 at 10:58 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,011
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Code:
    <body onclick = "redirect()">
    CLICK ANYWHERE ON THE PAGE TO REDIRECT AFTER 2 SECONDS
    
    <script type = "text/javascript">
    function redirect() {
    setTimeout('window.location = "http://www.google.com"', 2000);
    }
    
    </script>

    "More than any other time in history, mankind faces a crossroads. One path leads to despair and utter hopelessness. The other, to total extinction. Let us pray we have the wisdom to choose correctly."
    Woody Allen - US movie actor, comedian, & director (1935 - )

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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