Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-05-2011, 10:55 PM   PM User | #1
tridentspk
New Coder

 
Join Date: Jul 2011
Posts: 17
Thanks: 2
Thanked 0 Times in 0 Posts
tridentspk is an unknown quantity at this point
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..
tridentspk is offline   Reply With Quote
Old 09-06-2011, 11:12 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,102
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:00 PM.


Advertisement
Log in to turn off these ads.