JavaScript Random Redirect and Delay?

Discussion in 'HTML & Website Design' started by Menard, Nov 12, 2006.

  1. #1
    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, Nov 12, 2006 IP
  2. mani

    mani Peon

    Messages:
    679
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #2
    very simple... use a count down timer script to get your job done after a number of seconds.. you can use following link.. it has both count down and stopwatch.. see the source code of page to view the script source...

    http://www.jsr.communitech.net/stopwatch2.htm

    you can edit the script to go to the new page instead of displaying alert message.
     
    mani, Nov 12, 2006 IP
  3. Menard

    Menard Peon

    Messages:
    170
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #3
    :confused:

    Not too certain how that applies to my needs (as I need the redirect and delay to be automatic rather than depend on an input), but the site does mention the use of the meta refresh tag to redirect to a random link. They unfortunately redirect to anywhere but a page with the script. As I know the the meta refresh tag can be used to delay a redirect, can both of the functions; delay and random redirect; be combined into the meta refresh tag?
     
    Menard, Nov 12, 2006 IP
  4. SoKickIt

    SoKickIt Active Member

    Messages:
    305
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    70
    #4
    
    <script type="text/javascript">
    	
    	var urls = new Array("http://www.google.com/", "http://www.yahoo.com/");
    	
    	function redirect()
    	{
    		window.location = urls[Math.floor(urls.length*Math.random())];
    	}
    	
    	var temp = setInterval("redirect()", 3000);
    
    </script>
    
    Code (markup):

    3000 - you're redirected after 3 seconds.
     
    SoKickIt, Nov 12, 2006 IP
  5. Menard

    Menard Peon

    Messages:
    170
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Awesome :D

    It works perfectly.

    Thank You
     
    Menard, Nov 12, 2006 IP
  6. joet1110

    joet1110 Guest

    Messages:
    487
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Cheers it works great :)
     
    joet1110, Nov 21, 2007 IP
  7. iluminatus

    iluminatus Well-Known Member

    Messages:
    357
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    128
    #7
    Can this be done while hidding the ref url ?
     
    iluminatus, May 8, 2008 IP
  8. jemy

    jemy Peon

    Messages:
    70
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8


    man why two domains is this script rediret to the 2 page or what i dont understand why google and yahoo this script redirect only 1 time to the yahoo where is google ?
     
    jemy, May 8, 2008 IP
  9. psychakshay

    psychakshay Active Member

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    63
    Digital Goods:
    1
    #9
    Hey guys..
    I have this problem..
    I want to redirect my website to another site after every 10 visits..
    Any Help..
     
    psychakshay, Aug 15, 2011 IP