The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 18, 2019, 12:36:35 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Delay code execution  (Read 7554 times)
Docthorn
Rookie
**
Offline Offline

Posts: 10


View Profile
« on: April 22, 2007, 04:54:56 PM »

Question.

Is it possible to delay the execution of a javascript script?
For example I open somesite/page1 and after 5 seconds the page executes some javascript.

If not, can I get around this with a PHP page that after five seconds loads a frame, and inside the frame the page with the javascript code? I'm brainstorming a bit to find possible solutions so forgive me if what I said makes no sense.

Ciao,
Doc
Logged

No links in signatures please
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: April 22, 2007, 05:18:19 PM »

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
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Docthorn
Rookie
**
Offline Offline

Posts: 10


View Profile
« Reply #2 on: April 22, 2007, 10:33:59 PM »

Great. Simpler than I tought, thank you perkiset.

Doc
Logged

No links in signatures please
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #3 on: April 23, 2007, 08:49:35 AM »

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
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!