Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Common code errors

  1. #11
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,394
    Thanks
    32
    Thanked 153 Times in 147 Posts
    Blog Entries
    34

    Default

    Quote Originally Posted by boogyman View Post
    its invalid because it is not fully supported by all browsers.
    It's supported by almost all modern browsers now.
    Quote Originally Posted by boogyman View Post
    When dealing with IE, to accomplish the same affect, you would need to use
    Code:
    .innerText
    ???

    Quote Originally Posted by Twey View Post
    The HTML is valid, the Javascript is not.
    Right, that's it, thank you. The validators look at the HTML, not at the javascript.
    ===
    Arie.

  2. #12
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,394
    Thanks
    32
    Thanked 153 Times in 147 Posts
    Blog Entries
    34

    Default

    Now what to do in a situation in which the only thing that works in a specific browser is innerHTML?
    Here's an illustration of what I mean. If you want to dynamically create a text/htm-object, you can do the following in all browsers but IE:
    Code:
    function create_external(the_id,url,object_style)
    {
    var inserted=document.getElementById(the_id);
    }
    while (inserted.firstChild) {inserted.removeChild(inserted.firstChild);}
    OBJ = document.createElement("object");
    OBJ.setAttribute('type','text/html');
    OBJ.setAttribute('data',url);
    OBJ.setAttribute('style',object_style);
    inserted.appendChild(OBJ);
    }
    
    Usage: something like:
    href="#" onclick="create_external('some_id','bla.html', 'position:relative; width:190px; height:250px; background-color:yellow; left:0px; border:1px solid red;margin-top:9px'); return false; "
    But for IE, the only way to accomplish this is:
    Code:
    inserted.innerHTML='<object type="text/html" data="' + url + '", style="'+ object_style +'"><\/object>'
    (Attribute assignment doesn't work for IE in this particular case).
    In this situation, shouldn't we use innerHTML for the IE-case? (The only alternative is that we don't do it for IE).
    See this thread for an illustration.
    ===
    Arie.
    Last edited by molendijk; 08-26-2008 at 11:40 PM. Reason: Correction

  3. #13
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Of course, legacy methods can and should be used as fallback for legacy browsers, should one choose to support them. You fall foul of 3.2, though, and additionally have failed to provide support for non-JS browsers, which would also be an acceptable fallback for IE.

    setAttribute() and getAttribute() are never necessary in JS when dealing with HTML, and IE has some issues with them. They are used for programming languages which are incapable of looking up properties by a string name, and also for XML.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #14
    Join Date
    Apr 2006
    Posts
    429
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    nice.
    Please don't mind me. I am just posting a lot of nonsense.

  5. #15
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Code:
    setAttribute() and getAttribute() are never necessary in JS when dealing with HTML, and IE has some issues with them. They are used for programming languages which are incapable of looking up properties by a string name, and also for XML.
    ...They are simply called as what the functions says. "Attributes". It's pointless in JS because you also have this:

    Code:
    array["someItem"]
    For calling attributes as strings.
    Last edited by mburt; 08-29-2008 at 02:51 AM.
    - Mike

  6. #16
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    Best darned tips I've ever seen!!

    -magicyte

Tags for this Thread

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
  •