SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2002
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    check if external javascript file is loaded

    ive heard that there is a way to check if an external javascript file has loaded such as in the following example:

    Code:
    <script language='javascript' src="file.js"></script>
    what i want to know is if there is a way to tell when this file.js has loaded?
    on the Microsoft network is says that this is possible (http://msdn.microsoft.com/library/de...readystate.asp), however i do not know how to implement it.

  2. #2
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    if you put an onload in the JS it will trigger when the external JS has loaded.
    onload=alert("js loaded")

    To make an external onload trigger when the document has loaded use
    window.onload=function () {alert("doc loaded")}
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  3. #3
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could also check to see if a variable that is unique to the external javascript is available. If you had the variable "x" in the external script then after the include for the exteranl script you could do this:
    if(window.x) // is available
    {then do something}
    else // not available
    {do something else}


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
  •