Results 1 to 6 of 6

Thread: Calling Javascript not in head

  1. #1
    Join Date
    Nov 2009
    Posts
    107
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default Calling Javascript not in head

    I am hoping someone might be able to offer their thoughts on a problem I have. I need to call a javascript that should reside in the head of the page. Unfortunately I am locked into only being able to build mods. This means no <head> access. Is there a way to dock the script somewhere else and then call it in the mod? Any solutions or ideas would be helpful.

    Thanks.
    Last edited by itivae; 04-13-2012 at 11:03 AM.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    <script> tags work anywhere in the document, but loading order is important. For example:
    Code:
    <script src="my_script.js"></script>
    <script> var A = new my_script(); </script>
    works fine. However,
    Code:
    <script> var A = new my_script(); </script>
    <script src="my_script.js"></script>
    won't - your "my_script" hasn't loaded yet when you try to use it.

    So, to answer your question, "maybe." Couldn't say without knowing the specifics of your situation.

  3. #3
    Join Date
    Nov 2009
    Posts
    107
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    Thanks for the response. You always seem to be the one to answer my noob questions traq, so thanks for that

    I basically have an html mod that I need to put a jquery call or another javascript call into. However reading the installation instructions, they all say "insert call in the head of the doc." Sorry if this sounds like a stupid question, but can I call head javascripts from the body instead?

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    probably.

    again, without knowing the particulars I couldn't say. Try it and find out (just make a backup copy of your pages/scripts first).

  5. The Following User Says Thank You to traq For This Useful Post:

    itivae (04-13-2012)

  6. #5
    Join Date
    Nov 2009
    Posts
    107
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Default

    Calling from the body worked for this thanks.

  7. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    no prob

    If your question has been answered, please mark your thread "resolved":
    • On your original post (post #1), click [edit], then click [go advanced].
    • In the "thread prefix" box, select "Resolved".
    • Click [save changes].

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
  •