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

Discussion in 'Programming' started by skullcane, Sep 5, 2011.

  1. #1
    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.
     
    skullcane, Sep 5, 2011 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    Just use a jQuery click function (for the body) and a window.location. Just 2 lines of code, you don't need a script.
     
    Rukbat, Sep 5, 2011 IP
  3. skullcane

    skullcane Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Can you please show me the code that can do that?

    I'm not experienced with coding as much as I'am with being a webmaster.
     
    skullcane, Sep 5, 2011 IP
  4. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #4
    
    
    $('body').click(function() {
    
        window.location('http://www.myothersite.com/');
    
     });
    
    Code (markup):
     
    Rukbat, Sep 5, 2011 IP
  5. Agent89

    Agent89 Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    There's a ton of javascript repositories out there. You might be able to find what you're looking for there. Just do a Google search.
     
    Agent89, Sep 5, 2011 IP
  6. Rising_Star

    Rising_Star Active Member

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #6
    try this

    <body onclick="window.location='http://your-url.com';">

    ........................................
    ................
    your page
    ....................................
    .......................
    </body>
     
    Rising_Star, Sep 5, 2011 IP