Reply
Random Redirect and Delay?
Old 11-12-2006, 10:47 AM Random Redirect and Delay?
Menard's Avatar
Average Talker

Posts: 27
I have been searching for a JavaScipt to perform a specific function without any luck. I have found scripts for a redirection to a random site, but no delay.

What I am trying to accomplish is, after the visitor has clicked on a link they will be taken to a page which will then redirect then to a randomly selected site. However, I want to delay them on the page for a few seconds.

Can anyone recommend a script, or a way I can do this?
Menard is offline
Reply With Quote
View Public Profile Visit Menard's homepage!
 
When You Register, These Ads Go Away!
Old 11-13-2006, 09:52 PM Re: Random Redirect and Delay?
Extreme Talker

Posts: 177
You can use setTimeout in JavaScript to 'delay' or 'pause', but you may want to use the following in HTML (not JavaScript)

The following example will wait 3 seconds, then redirect the browser to http://www.webmaster-talk.com
HTML Code:
<META HTTP-EQUIV="Refresh" CONTENT="3;URL=http://www.webmaster-talk.com">
This is assuming, of course, that you can insert the random URL into the code above.
__________________
Bulbous Bouffant

Last edited by CouponGuy : 11-13-2006 at 09:54 PM.
CouponGuy is offline
Reply With Quote
View Public Profile
 
Old 11-13-2006, 10:40 PM Re: Random Redirect and Delay?
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Wireless Audio
Posts: 2,320
Name: Keith Marshall
Location: West Hartford, CT
Using CouponGuy's idea, I played around and came up with a following solution. The script has to reside inside the html header for it to work properly.

HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <title>Random JS Page Jump</title>
  <script type="text/javascript" language="javascript">
  <!--// Random JS Page Jump Code
    
    var jumpTo = new Array();
    
    // Define possible url jumps
    jumpTo[0] = 'http://www.webmaster-talk.com';
    jumpTo[1] = 'http://www.google.com';
    jumpTo[2] = 'http://www.apple.com';
    jumpTo[3] = 'http://www.microsoft.com';
    
    // Define random function
    function getRandom() {
      return Math.floor(Math.random() * jumpTo.length);
    }
    
    // Output meta refresh tag
    javascript: document.write('<META HTTP-EQUIV="Refresh" CONTENT="3;URL=' + jumpTo[getRandom()] + '">');
    
  //-->
  </script>
  </head>
  <body>
    Random JS Page Jump
  </body>
</html>
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 11-15-2006, 04:19 PM Re: Random Redirect and Delay?
Menard's Avatar
Average Talker

Posts: 27
Awesome! Thank you for providing that. I'll let you know how it works for me.
Menard is offline
Reply With Quote
View Public Profile Visit Menard's homepage!
 
Reply     « Reply to Random Redirect and Delay?
 

Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13937 seconds with 12 queries