SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    506
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    window.setTimeout();

    Folks,

    I have some javascript that redirects to another url, but i want my script to execute another block of code before it redirects. Basically, I want to pass some values to a url like so:
    PHP Code:
    document.write('<img src="http://url.com?fr=sdsds4&postMethod=HTML&m=0&j=MAS2&Email='+Email+'&Address 1='+A1+'&Address 2='+A2+'&Birthdate='+DOB+'&City='+CI+'&First Name='+FirstName+'&Gender='+Gender+'&Last Name='+LastName+'&Phone Number='+PH+'&State='+ST+'&Zip Code='+ZIP+'" width="100" height="100">'); 
    and once the above block is done then redirect like so:
    PHP Code:
    var vRURL=location.
    vRURL=vRURL.replace("link1","link3");
                        
    var 
    vURL="http://url.com/consumers.Redirect?rid="+FirstName+LastName+Email;
                
    location.href=vURL
    So I have been using the window.setTimeout('doit()',70000); just before the redirect, but window.setTimeout() is not doing anything. Does anyone please know how I can do this?

    my full code is like so
    PHP Code:

    document
    .write('<img src="http://url.com?fr=sdsds4&postMethod=HTML&m=0&j=MAS2&Email='+Email+'&Address 1='+A1+'&Address 2='+A2+'&Birthdate='+DOB+'&City='+CI+'&First Name='+FirstName+'&Gender='+Gender+'&Last Name='+LastName+'&Phone Number='+PH+'&State='+ST+'&Zip Code='+ZIP+'" width="100" height="100">');

     
    window.setTimeout('doit()',70000);

    var 
    vRURL=location.
    vRURL=vRURL.replace("link1","link3");
                        
    var 
    vURL="http://url.com/consumers.Redirect?rid="+FirstName+LastName+Email;
                
    location.href=vURL

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,198
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    70000 is a little high as its 70 seconds, if you don't already know javascript uses milisecond based timeout values. Moving on though the above code you have is missing the function called doit() which i assume executes the code below the setTimeout declaration.

    If I'm mistaken let me know but i think the below is what you what...

    Code JavaScript:
    document.write('<img src="http://url.com?fr=sdsds4&postMethod=HTML&m=0&j=MAS2&Email=' + Email + '&Address 1=' + A1 + '&Address 2=' + A2 + '&Birthdate=' + DOB + '&City=' + CI + '&First Name=' + FirstName + '&Gender=' + Gender + '&Last Name=' + LastName + '&Phone Number=' + PH + '&State=' + ST + '&Zip Code=' + ZIP + '" width="100" height="100">');
     
    window.setTimeout(function() {
        var vRURL = location;
        vRURL = vRURL.replace("link1", "link3");
     
        var vURL = "http://url.com/consumers.Redirect?rid=" + FirstName + LastName + Email;
        location.href = vURL;
    }, 1000);

    Also on a side note i noticed you have spaces in your URL parameters which is a big NO NO in the web development world as in the past browsers have been known to handle spaces differently. I would recommend you change the names to have underscores and update the script receiving the values so its 100% browser compliant.

  3. #3
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    506
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SgtLegend View Post
    70000 is a little high as its 70 seconds, if you don't already know javascript uses milisecond based timeout values. Moving on though the above code you have is missing the function called doit() which i assume executes the code below the setTimeout declaration.

    If I'm mistaken let me know but i think the below is what you what...

    Code JavaScript:
    document.write('<img src="http://url.com?fr=sdsds4&postMethod=HTML&m=0&j=MAS2&Email=' + Email + '&Address 1=' + A1 + '&Address 2=' + A2 + '&Birthdate=' + DOB + '&City=' + CI + '&First Name=' + FirstName + '&Gender=' + Gender + '&Last Name=' + LastName + '&Phone Number=' + PH + '&State=' + ST + '&Zip Code=' + ZIP + '" width="100" height="100">');
     
    window.setTimeout(function() {
        var vRURL = location;
        vRURL = vRURL.replace("link1", "link3");
     
        var vURL = "http://url.com/consumers.Redirect?rid=" + FirstName + LastName + Email;
        location.href = vURL;
    }, 1000);

    Also on a side note i noticed you have spaces in your URL parameters which is a big NO NO in the web development world as in the past browsers have been known to handle spaces differently. I would recommend you change the names to have underscores and update the script receiving the values so its 100% browser compliant.
    Thank you, Yes your code works. I was able to get this also to work by doing this way:

    PHP Code:
    vURL="http://url.com/consumers.Redirect?rid="+FirstName+LastName+Email;
                
    setTimeout("location.href = vURL;",700); 
    About the spaces yes that I need to correct and yes I dont program in js a lot, but php.

    thanks you though.

  4. #4
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,198
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Your welcome


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •