can setTimeout() call other function within a function? or a local object's sub-func?
hi,
see, i popup a page and simply close it immediately:
HTML Code:
function doPost() {
var bump = window.open('some.html','');
bump.close();
return false;
}
which works with no aim.. now i want to do it again with delay which means setTimeout() !!
HTML Code:
function doPost() {
var bump = window.open('some.html','');
setTimeout("bump.close()", 3000);
return false;
}
result is Reference to undefined variable : bump because bump is not global. well i cant either make it another function and call by setTimeout() which is already in a function..
any idea ? tnx
popup page is NOT editable so no onLoad="" as well...
who the dummy designed that setTimeout() function, idiot JS core developer !!
but then bump window will be opened instantly the page loads which i dont prefer. I want to call it within the function launchs. like some form's onSubmit
and another fix solition is put it out of function as you said and close it right again which is not professional...
You should try to avoid using popups as some systems and newer systems which are upto date with latest patches will block popups. Most firewalls will also block pop-ups, cookies and other methods of delivery of advertising.
IF you must advertise, your better off delivering banners to your web site page that rotate or change with eash page click, etc.
Using .setTimeout() for a task that is going to repeat, use the .setInterval() as this only needs setting once and if you use currentID=window.setInterval(myfunc,60000); will setup a reference to the event, this can be used to stop the interval with clearInterval(currentID); so you can call a routine and it will be called (in this case every 60 seconds) every 60000 milliseconds.
I built a banner script that used a system of set & clearInterval to alter the display length of the images so that slideshows can be made up where several images can be played at varying rates or held for as log as required.
Bookmarks