NameSilo

Simple Javascript delay help needed

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Spacemail by SpaceshipSpacemail by Spaceship
Watch

youngempire

Established Member
Impact
3
I need some quick help to setup a delay on my javascript code below so that there will be a 15 second delay before the javascript code executes.

Code:
<script type="text/javascript" src="example.js">
</script>

I tried the setTimeout function but could not get it to work. Any help is greatly appreciated! :D
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
your example.js must be in the same dir with file include
 
0
Close
0
Close
0
Close
setTimeout("function expression",delaytime)

how do I setup the src="example.js" so that it is a function?

i.e.
Code:
function fetch(){
"example.js"
setTimeout("fetch",2000);
}

Any ideas?
 
0
Close
you would have to define a function that either contains all of the functions of example.js (or find the name of the one function found in example.js) and call that.
 
0
Close
you would have to define a function that either contains all of the functions of example.js (or find the name of the one function found in example.js) and call that.

Right this is what I don't know how to do and am seeking help with.
 
0
Close
ah ok, in that case, it woudl depend on how your example.js file is laid out. do you have a copy/example of it? (lol)
 
0
Close
ah ok, in that case, it woudl depend on how your example.js file is laid out. do you have a copy/example of it? (lol)

Sorry I don't. But the original code above with the src="example.js" works fine, I just need help putting a delay on it.
 
0
Close
ok well the way that javascript works is that on some event, it runs some code. this code that it runs can be defined as a function (and therefore given a name). i honestly cant help you to get the exact code without seeing example.js, as it could have a multitude of things.

like if it were just:

Code:
function popup() {
alert("Hi!");
}

then, the function name in setTimeout would be "popup". However, most javascript scripts are much more complex and call a variety of functions, so you'd probably have to remove whatever trigger is making it run (it could be a onLoad in the body html tag, for example), consilidate it so it can be run by one function call, and then use that for the setTimeout.

if you don't want to post the example.js file here, i'm open to PMs
 
0
Close
Put everything you want to do in a function, then call the function in the setTimeout function.

Try put the following in your page, and the alert will pop up 3 seconds after the page is loaded.

<script>

function popup() {

alert('Hi!');

}

setTimeout('popup()',3000);

</script>
 
0
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back