www.webdeveloper.com
Results 1 to 6 of 6

Thread: [RESOLVED] A Way To "Stall" Execution of Certain Scripts

  1. #1
    Join Date
    Mar 2010
    Posts
    6

    resolved [RESOLVED] A Way To "Stall" Execution of Certain Scripts

    So I'm working with some simple JavaScript/HTML, and I'm trying to figure out if there's a way to "stall" the execution of certain JS scripts. My code is as follows:

    HTML Code:
    <script type="text/javascript" src="/js/fullmin.js"></script>
    <script type="text/javascript" src="/js/execute.js"></script>
    Unfortunately, due to the agreement I have with the developer of those two scripts, I'm not allowed to modify them in any way, otherwise this would probably be much easier. I thought of using PHP's sleep() before those two lines are sent to the end-users, but that pauses the execution of the rest of the page.

    Is there something I could do to have some type of "pause" or something before those two lines are actually executed in the end-user's browser? I thought maybe using something like JsvaScript's setTimeout(), but would there be a way to include those JavaScript files inside a JavaScript function instead of via HTML if I were to do that?

    I feel like I'm asking the impossible, but any insight would be greatly appreciated.

  2. #2
    Join Date
    Mar 2010
    Posts
    2,803
    I'm a little confused

    I doubt there is a way to stall the execution of whatever is inside those scripts while they are being downloaded to the browser.

    By stalling them, if it can be done, implies that you are happy to let them run at a later stage as opposed to blocking or deleting them alltogether, so maybe if you explain why you need to stall them and what you would like to do while they are stalling then maybe someone can help.


  3. #3
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Post loading the scripts is doable, but it may prevent the scripts running correctly.
    At least 98% of internet users' DNA is identical to that of chimpanzees

  4. #4
    Join Date
    Mar 2010
    Posts
    6
    The two scripts work together to create an advanced dynamic popup of ads. As of right now, they run immediately after they are loaded. I would like for them to popup after about 30 seconds. I have asked the developer to modify the code to do that, but he refuses, and I'm not allowed to do it. Since my site is a commercial site, I'd prefer not to break his TOS.

  5. #5
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Try this to delay adding the scripts:
    Code:
    window.onload=function() {
    var delay = 30000; // 30 sec
    setTimeout(function(){addScript('fileName1.js');addScript('fileName2.js');}, delay);
    };
    
    function addScript(JSfileName) {
    var js = document.createElement('script');
    js.setAttribute('type', 'text/javascript');
    js.src = JSfileName;
    document.body.appendChild(js);
    }
    At least 98% of internet users' DNA is identical to that of chimpanzees

  6. #6
    Join Date
    Mar 2010
    Posts
    6
    Thank you SOO much. That worked perfectly. Originally, I tried writing the necesarry script elements via document.write() until I realized that document.write() can't be used after the page is fully loaded. Otherwise it would overwrite the entire page.

    Thanks again for your help. It works like a charm.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles