SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Feb 2002
    Location
    Kuwait
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to execute external JS files after page done?

    Hi,

    I have a dynamic (PHP) external JavaScript file. I need to load that file every X seconds and execute its contents, given the the page is already 'Done' (fully downloaded).

    How can this be done?

    TIA.

  2. #2
    morphine for a wooden leg randem's Avatar
    Join Date
    Jun 2002
    Location
    .chicago.il.us
    Posts
    957
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: How to execute external JS files after page done?

    ...I need to load that file every X seconds and execute its contents...
    Are the contents of this file going to be different when you reload it?
    ----Adopt-a-Sig----
    Your message here!

  3. #3
    SitePoint Member
    Join Date
    Feb 2002
    Location
    Kuwait
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes. I'm using PHP to dynamicly produce the JS output with each request. The output will be in the form of JS function calls to do different things (e.g.: display a chat message submitted by someone).

  4. #4
    morphine for a wooden leg randem's Avatar
    Join Date
    Jun 2002
    Location
    .chicago.il.us
    Posts
    957
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe something like this?
    Code:
    nSeconds = 5;
    scriptURL = '/javascript.js';
    
    function reloadscript(){
      document.write('<scr'+'ipt type="text/javascript" src="'+scriptURL+'"></scr'+'ipt>');
      setTimeout('reloadscript()', nSeconds*1000);
    }
    ----Adopt-a-Sig----
    Your message here!

  5. #5
    SitePoint Member
    Join Date
    Feb 2002
    Location
    Kuwait
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, that is what I wanted to do, until I learned that you can't 'document.write' something after the document is loaded.

  6. #6
    morphine for a wooden leg randem's Avatar
    Join Date
    Jun 2002
    Location
    .chicago.il.us
    Posts
    957
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay... how about putting the page into a frameset with a hidden frame which reloads every 5 seconds and executes the javascript? You'd only have to alter the javascript to work across the frames... not too hard.
    ----Adopt-a-Sig----
    Your message here!

  7. #7
    SitePoint Member
    Join Date
    Feb 2002
    Location
    Kuwait
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool

    Great Idea! Thanks a lot


Bookmarks

Posting Permissions

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