SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    IL
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JS call in the header that is not used in the body creates an error

    Hi,

    I have a few calls to JS in the header file of a CMS. This header file is included to all site's pages:

    Code:
    <script type="text/javascript" language="javascript" src="...site.../ajax-dynamic-content.js"></script>
    <script type="text/javascript" language="javascript" src="...site.../ajaxtabs.js"></script>
    The problem is that these JS are not used on every page of the site. Sometimes it's in the body of a page and sometimes not.

    When it's used on the page there's no problem.

    When it's not - there's an error:

    On IE it shows this exclamation mark at the bottom left corner and says 'null' is null or not an object.

    On FF error console it has the error: ulobj is not an object.


    How can i fix this ?? There's no other way to include these calls on every page outside of the header file - this is the structure of this system..

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You could create an object with the ID it's looking for, and set its style to display:none to hide it?

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    IL
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And i'll have to put it in each and every page ? That's a lot of work and also a waste of server resources isn't it ?

    There's no easier solution ?

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Don't you have a template for the footer you could put it in? Not sure how I could formulate an easier solution for conditionally including code in a mystery CMS (hint hint...)

    You can always open up the JavaScript files and rewrite them to check for the existence of the objects they're trying to modify before they go doing so.

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    IL
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahhh ! The footer Great idea.. Why haven't I thought of this before? lol..

    The other solution is too much for my (lack of) JS knowledge..

    Just to be sure what do you mean by "set its style to display:none" ?

    If that's the call:

    <script type="text/javascript">
    startajaxtabs("feedtab","acctab")
    </script>

    What should i do ?

  6. #6
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change your JS code to first check if the element is present, if it isn't exit the script.
    mmj

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Zenmaster View Post
    <script type="text/javascript">
    startajaxtabs("feedtab","acctab")
    </script>

    What should i do ?
    It depends on the code in that function and which statement in the function is giving the error.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    IL
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've tried a few things (besides editing the JS which i don't know how) but they didn't work..

    The script is Ajaxtabs. There are a few scripts but this is the one that cause the error: download

    This is the line giving the error:

    Code:
    var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL
    The error is (on FF console): ulobj has no properties

    Thanks!

  9. #9
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Zenmaster View Post
    I've tried a few things (besides editing the JS which i don't know how) but they didn't work..

    The script is Ajaxtabs. There are a few scripts but this is the one that cause the error: download

    This is the line giving the error:

    Code:
    var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL
    The error is (on FF console): ulobj has no properties

    Thanks!
    Change that to:

    Code javascript:
    if (ulobj)
    	var ulist=ulobj.getElementsByTagName("li")
    else
    	return;
    mmj

  10. #10
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    IL
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It worked

    Thank you very very much !

    E-A.


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
  •