Forum Moderators: open

Message Too Old, No Replies

Problem with settimeout under IE.

         

nelsonm

9:30 pm on Mar 24, 2011 (gmt 0)

10+ Year Member



I'm having trouble with the setTimeout function. It works with all browsers on all of my machines except one machine under IE.

The following function is called onload of the page. I could use a little help on setting this function up to work with everything. After some research, i thought the following would work, but it does not work on one Windows 7 x64 installation with IE8 or 9.

function timeOut(xForm,mlsPreset,chaPreset,aomPreset,milPreset,posPreset){
var mlsPreset, obj = document.getElementById('intro');
var xForm, chaPreset, aomPreset, milPreset, posPreset;

clearTimeout(obj.to);
ftn = "gotoIntro('" + xForm + "','" + chaPreset + "','" + aomPreset + "','" + milPreset + "','" + posPreset + "')";
obj.to = setTimeout(ftn,mlsPreset);
}


would it be better if i structured it like the following?

obj.to = setTimeout(function(){gotoIntro(xForm,chaPreset,aomPreset,milPreset,posPreset);},mlsPreset);


Another thought since it works on all other windows 7 x64 machines under IE8&9 except one, is that there is some IE configuration on that machine that is messed up?

The machine in question is a new HP TouchSmart 600 all-in-one touchscreen pc. What could i tweak in IE or the PC configurations?

daveVk

3:06 am on Mar 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



function timeOut(xForm,mlsPreset,chaPreset,aomPreset,milPreset,posPreset){
var mlsPreset, obj = document.getElementById('intro');
var xForm, chaPreset, aomPreset, milPreset, posPreset;

Why are these parameters being redeclared as local vars ?, delete red stuff maybe.

nelsonm

3:43 am on Mar 25, 2011 (gmt 0)

10+ Year Member



A lapse in judgement on the local variables but it should not cause a problem.

My understanding is that the following is the way to go...

function timeOut(xForm,mlsPreset,chaPreset,aomPreset,milPreset,posPreset){
var obj = document.getElementById('intro');

clearTimeout(obj.to);
obj.to = setTimeout(function(){gotoIntro(xForm,chaPreset,aomPreset,milPreset,posPreset);},mlsPreset);
}

daveVk

8:57 am on Mar 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



when this function executes

function(){gotoIntro(xForm,chaPreset,aomPreset,milPreset,posPreset);},mlsPreset);
}

I do not think variables mentioned will be available unless you make them global.

If you wish to go that way, you will probably need a closure.

I would start by putting
alert( ftn );
in original code, to check whats being passed it.

nelsonm

3:55 pm on Mar 25, 2011 (gmt 0)

10+ Year Member



I added an alert to test the passing of local variables and parameters in the function call. The values are being passed.

Here is the full code. As you can see, i put the alert in the function call being timed. Basically, it's just displaying a hidden div on the page after the timeout.

function gotoIntro(xForm,mlsPreset,chaPreset,aomPreset,milPreset,posPreset){

alert('timeOut -\nxForm:'+xForm+'\n, mlsPreset:'+mlsPreset+'\n, chaPreset:'+chaPreset+'\n, aomPreset:'+aomPreset+'\n, milPreset:'+milPreset+'\n, posPreset:'+posPreset);

var radio = $(".rb"), checkbox = $(".cb");

document.getElementById('intro').style.display = 'block';
document.getElementById('msg-area').style.display = 'block';
document.getElementById('list-area').style.display = 'none';

for(i=0; i < radio.length; i++){if(chaPreset.charAt(i) == "1" ){radio[i].checked = true;}else{radio[i].checked = false;}}
for(i=0; i < checkbox.length; i++){if(aomPreset.charAt(i) == "1" ){checkbox[i].checked = true;}else{checkbox[i].checked = false;}}

document.charitiesform.mile.value = milPreset;
document.charitiesform.postalcode.value = posPreset;

hdrAlert('reset');
}


function timeOut(xForm,mlsPreset,chaPreset,aomPreset,milPreset,posPreset){

var obj = document.getElementById('intro');

clearTimeout(obj.to);
obj.to = setTimeout(function(){gotoIntro(xForm,mlsPreset,chaPreset,aomPreset,milPreset,posPreset);},mlsPreset);
}

Fotiman

4:53 pm on Mar 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Try adding a similar alert within your anonymous function that gets called by setTimeout.


obj.to = setTimeout(function(){
alert('anon -\nxForm:' + xForm +
'\n, mlsPreset:' + mlsPreset +
'\n, chaPreset:' + chaPreset +
'\n, aomPreset:' + aomPreset +
'\n, milPreset:' + milPreset +
'\n, posPreset:' + posPreset);
gotoIntro(xForm,mlsPreset,chaPreset,aomPreset,milPreset,posPreset);
},mlsPreset);

nelsonm

7:17 am on Mar 26, 2011 (gmt 0)

10+ Year Member



variables where passed to anonymous function as well so things look good.

The only problem I've encountered is that IE appears to mess with the javascript settimeout function. Sometimes it works and other times it does not. I have read that it may be do to caching issues in IE.