
![]() |
Docthorn
Question.
Is it possible to delay the execution of a javascriptscript?For example I open somesite/page1 and after 5 seconds the page executes some javascript.If not, can I get around this with a PHPpage that after five seconds loads a frame, and inside the frame the page with thejavascriptcode? I'm brainstorming a bit to find possible solutions so forgive me if what I said makes no sense.Ciao, Doc perkiset
Very simple:
setTimeout('theFunctionYouWantToCall()', 5000); This would do exactly what you are trying to accomplish, provided the function had your redirect code... function theFunctionYoWantToCall() { top.lcation='http://www.spamsite.com'; } You may also put pure code right in there: setTimeout("top.location='http://www.thespamsite.com'", 5000); /p Docthorn
Great. Simpler than I tought, thank you perkiset.
Doc perkiset
No worries.
Since we're at it, there is another handy function along these same lines: setInterval(jsCode, intervalMS) which does the same as setTimeout except that it does it repeatedly at intervalMS. Excellent for beacons and such. /p |

Thread Categories

![]() |
![]() |
Best of The Cache Home |
![]() |
![]() |
Search The Cache |
- Ajax
- Apache & mod_rewrite
- BlackHat SEO & Web Stuff
- C/++/#, Pascal etc.
- Database Stuff
- General & Non-Technical Discussion
- General programming, learning to code
- Javascript Discussions & Code
- Linux Related
- Mac, iPhone & OS-X Stuff
- Miscellaneous
- MS Windows Related
- PERL & Python Related
- PHP: Questions & Discussion
- PHP: Techniques, Classes & Examples
- Regular Expressions
- Uncategorized Threads