SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Zealot websalacarta's Avatar
    Join Date
    May 2003
    Location
    Spain
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question load javascript file dinamically

    Hi,
    I´m using this javascript to load one js file (params.js)

    Code:
    loadScript:function(file){
     	script = document.createElement('script');
      	script.src = file;
    	script.type = 'text/javascript';
    	document.getElementsByTagName("head")[0].appendChild(script);
    }
    params.js has only a few vars
    Code:
    paramPant = new Array();
    paramPant['param1'] = 5;
    paramPant['param2'] = 6;
    when this file is loaded, it´s suposse I can access paramPant value.

    It works correctly with IE6, but it doesn´t work with Firefox2 (it says paramPant is not defined)

    any idea why it doesn´t work with firefox?

    thanks very much.
    Last edited by websalacarta; Aug 14, 2007 at 02:45. Reason: write it easier to understand

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2007
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try
    paramPant = new Object();
    rather than an Array.

  3. #3
    SitePoint Zealot websalacarta's Avatar
    Join Date
    May 2003
    Location
    Spain
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nothing changes, the same problem with firefox.

    Thanks for your reply

  4. #4
    SitePoint Evangelist
    Join Date
    Jul 2007
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Firefox doesn't seem to wait for the script to load before carrying on. You may be using paramPant before the script is loaded and hence it is undefined.

    You can attach onload events to your script tag.
    script.onload = function() {alert(paramPant['param1'])};


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
  •