SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Debugging JavaScript for Internet Explorer

    I've been working on a page at http://www.politix.us/world/eur/afg/index.php, focusing particularly on some JavaScript functions. I've been previewing it in Firefox, where it looks pretty good (to me, anyway). When I checked it in Internet Explorer, I was horrified.

    It was even worse than what you see now. I fixed a CSS bug or two. But the most obvious problem is my "Features" feature. In Firefox, the word "Features" appears in the top right corner of the page. Click it, and it vanishes, replaced by an element that pops open on the opposite side of the page. Kill the JavaScript, and all the JavaScript elements automatically open, with the Features pop-up falling to the bottom of the page.

    I don't have a clue about validating, checking or fixing JavaScript. But I clicked "JavaScript Console" on Firefox and got a long list of errors. Actually, it's mostly one error listed over and over and over:

    PHP Code:
    document.getElementById(rest_of_articles[i]) 
    This appears to be what it's referring to:

    PHP Code:
    for(var i=0rest_of_articles.lengthi++)
    {
         
    document.getElementById(rest_of_articles[i]).className="no_display";
         
    document.getElementById(more_links[i]).className="display_link";

         
    document.getElementById(more_links[i]).onclick=more_article;
         
    document.getElementById(collapse_links[i]).onclick=collapse_article;

    Can someone tell me what this means, and advise me how to fix it?

    Here's another error that's displayed several times:

    PHP Code:
    WarningNon-standard document.all property was used. Use W3C standard document.getElementById() instead.
    Source Filehttp://us.js1.yimg.com/us.yimg.com/lib/pim/r/medici/7_31_2/mail/mailcommonlib.js
    Line13 
    I don't have a clue what they're talking about. I noticed still other errors that reference links to other websites. Fortunately, Firefox seems to handle it. I just need to make this work in IE.

    Thanks.

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because of the way 'initialize()' is written, the IDs assigned to these arrays must exist:
    Code:
    var rest_of_articles=new Array("rest_of_navfeatures", "rest_of_art1", "rest_of_art2", "rest_of_gov");
    var more_links=new Array("more_navfeatures", "more_art1", "more_art2", "more_gov");
    var collapse_links=new Array("collapse_navfeatures", "collapse_art1", "collapse_art2", "collapse_gov");
    In your html, 'rest_of_gov' is commented out, and 'rest_of_art1' and 'rest_of_art2' do not exist.

    Also because of the way 'initialize()' is written, more_links[] and collapse_links[] must have the same number of IDs as rest_of_articles[].

    'initialize()' could be rewritten as follows. Now, non-existent IDs will not cause an error (in this function only - i haven't looked any further than this) and the three arrays don't have to be the same length.
    Code:
    function initialize()
    {
      var ele;
      for(var i=0; i < rest_of_articles.length; i++) {
        ele = document.getElementById(rest_of_articles[i]);
        if (ele) {
          ele.className = "no_display";
        }
      }
      for(var i=0; i < more_links.length; i++) {
        ele = document.getElementById(more_links[i]);
        if (ele) {
          ele.className = "display_link";
          ele.onclick = more_article;
        }  
      }
      for(var i=0; i < collapse_links.length; i++)
      {
        ele = document.getElementById(collapse_links[i]);
        if (ele) {
          ele.onclick = collapse_article;
        }
      }
    }
    There are other errors. But let's take care of these first


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
  •