Jump to content

settimeout


joecool2005

Recommended Posts

Hi,this is the code:---------------------------------------var str=""function test1(id) { id=true setTimeout("test2(\"" + id+ "\")",1000);}function test2(id){ if(id) str="hello"; }var bool=""test1(bool)alert(str)---------------------------------------I have problem with settimeout. Why str is still empty?Thx Joe

Link to comment
Share on other sites

Why str is still empty?
str is still empty because your test2() is not called until 1 second has passed.You'll need to test the variable after the setTimeout has had time to work like:
var str=""function test1(id) {id=truesetTimeout("test2(\"" + id+ "\")",1000);}function test2(id){if(id)str="hello";}var bool=""test1(bool)setTimeout('alert(str)', 1500);

-hs

Link to comment
Share on other sites

Thank you.But now on my code I'm trying to do like you did.---------------------------------------------------------------var oWindowsT = new Object();var popupBlocked="";openWindowCheck("http://www.w3schools.com");function openWindowCheck(pageId) { var sPar = "width=500,height=500"; handle = window.open(pageId,"test",sPar); oWindowsT[pageId] = handle; setTimeout("checkOpen(\"" + pageId+ "\")",1000);}function checkOpen(pageId) { var popupBlocked=((!oWindowsT[pageId]) || (oWindowsT[pageId].closed)) ? true : false; }setTimeout('alert(popupBlocked)', 1500);---------------------------------------------------------------The popupBlocked variable is still empty. Do you know why? I supposed to see true or false.ThxJoe

Link to comment
Share on other sites

You do not want to use var when setting the variable in your function, that makes it a local variable.

function checkOpen(pageId) {var popupBlocked=((!oWindowsT[pageId]) || (oWindowsT[pageId].closed)) ? true : false;}

-to-

function checkOpen(pageId) {popupBlocked=((!oWindowsT[pageId]) || (oWindowsT[pageId].closed)) ? true : false;}

-hs

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...