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:


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:


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



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;

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…

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:


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.

Your welcome