SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    May 2000
    Location
    UK
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know you can use the onload statement to start a javascript when the page has loaded, but is there a statement that can start a javascript as soon as the page starts to load?
    Joel Moss
    ========================
    HomepageUniverse - Names, Tools & Hosting

  2. #2
    One website at a time mmj's Avatar
    Join Date
    Feb 2001
    Location
    Melbourne Australia
    Posts
    6,282
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I am not an expert, but if you put a javascript statement into the head section of a file eg

    <html>
    <head>
    <script language="javascript">
    <!--
    function dothis()
    {
    // include stuff here
    }
    dothis();

    // -->
    </script>
    </head>
    <body>
    <!-- Body of your html -->
    </body>
    </html>

    Then dothis() is run before loading the rest of the file.
    [mmj] My magic jigsaw
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The Bit Depth Blog · Twitter · Contact me
    Neon Javascript Framework · Jokes · Android stuff

  3. #3
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can probably use the "RUNAT" Attribue As well.

    For example:
    Code:
    <Script LANGUAGE="JavaScript" RUANT="Server">
    Hope this helps!
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  4. #4
    SitePoint Member
    Join Date
    Dec 2000
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not so sure if the RUNAT will work, but don't take my word for that. I was under the impression that specifying RUNAT="server" is used for server-side scripting, such as ASP (although it is much more commonly used implicity as simple <% %> delimiters). However, just entering code in the head, below the title and before the style sheets will run code as soon as it is downloaded. Be careful, as this can cause errors! Hope I helped!

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    Dłn Éideann, Alba
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok ...

    Firstly, don't put any functions in header if you want them to run when the page starts to load because functions only work when they are called by an event-handler.

    If you want to use a function (in order to make it common to multiple pages) put the function in a seperate JS file, and then call the function from an inline-script inside the head of the document. Like thus ...

    <html>
    <head>
    <script language=javascript type="text/javascript" src="yourfilename.js">

    <script language=javascript type="text/javascript" >
    <!-- // hide from old browsers

    window.load = yourFunction() ;
    // -->
    </script>
    </head>

    That should work just nicely ...

    Cheers. Scot-Bot. )

    </head>


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
  •