I have a script that I want to delay. I'm a Javascript noob obviously. So what I'm asking is how can I get this script to load 15 seconds after the page loads (it's called inside the <head></head> tags): <script type="text/javascript" src="lock.js"></script> I want to get lock.js to start 15 seconds after the page loads, in short. EDIT: I put this in the wrong place, sorry.
You will have to encapsulate the logic you want to execute in a function. Then, call that function like this: setTimeout(functionName,15000); Code (markup):
This isn't my code, I bought this (BlackHatCodeBreaker) and it's all encoded, so I have no idea what the function name is, I just need the general script to be executed later, anyway to do that without having to know the functions. Maybe a better question to ask is can you write a function that executes a javascript file?
Yes, you can also try and include the script later like so: <script type="text/javascript"> function loadLock() { var html_doc = document.getElementsByTagName('head').item(0); var js = document.createElement('script'); js.setAttribute('language', 'javascript'); js.setAttribute('type', 'text/javascript'); js.setAttribute('src', 'lock.js'); html_doc.appendChild(js); } setTimeout(loadLock,15000); </script> Code (markup): However, keep in mind that the file will only be included after 15 seconds, so this is without downloading etc. You may want to change it to 13 or 14 seconds to compensate.
Hm...didn't work. EDIT: I think it's because I have 2 iframes with really long videos in them...it's trying to load them fully before it pops up.
You can just add an alert in the function: alert('test'); See if that pops up after 15 seconds. If it does, everything should be in order and there is a problem with your script.