Web Analytics Made Easy -
StatCounter Code that automatically redirects a visitor after they click anywhere on the page? - CodingForum

Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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; Sep 5, 2011, 05:58 PM.

  • #2
    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.

    Comment

    Working...
    X
    😀
    🥰
    🤢
    😎
    😡
    👍
    👎