Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    New to the CF scene
    Join Date
    Mar 2003
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Detecting DOM Support in a browser....

    Is this possible -- can somebody give me a code snippit to detect if a browser supports DOM level 1

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    generally, document.getElementById and document.createElement are useful object tests for this.

    However, Opera 6 returns a function for createElement, even though it can't add the created element to the page. So to cater for that, I'd do something like this:

    var agt = navigator.userAgent.toLowerCase();
    var op6 = (agt.indexOf("opera/6")!=-1||agt.indexOf("opera 6")!=-1)?true:false;

    var DOM = (typeof document.getElementById!="undefined" && typeof document.createElement!="undefined" && !op6)?true:false;
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #3
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    try testing for document.implementation
    Last edited by liorean; 03-11-2003 at 08:14 PM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by liorean
    try testing for document.implementation
    Much better But isn't that DOM2 ?
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #5
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    cool
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #7
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    var dom1 = document.implementation && document.implementation.hasFeature('XML', '1.0') && document.implementation.hasFeature('HTML', '1.0');

    That should be pretty accurate, if vendors do what they are supposed to.

  • #8
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Might be a good idea to remove the DOM1 XML check, as IE is stupid... and apparently so is Opera. hmph

    var dom1 = document.implementation && document.implementation.hasFeature('HTML', '1.0');

  • #9
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Hey - using strict warnings?

    try this

    var dom1=('implementation' in document)&& document.implementation.hasFeature('HTML', '1.0');

    or, a bit longer but more backwards compatible:

    var dom1=(typeof document.implementation!='undefined')&& document.implementation.hasFeature('HTML', '1.0');
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #10
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by liorean
    var dom1=('implementation' in document)
    Hey that's interesting. I didn't realise you could use in like that
    Last edited by brothercake; 03-11-2003 at 10:49 PM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #11
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Yeah, I know. I've only seen it used internally in Mozilla/Netscape code before I started using it. I have no idea how the support for it is, except that op7, moz and jscript5.6 (comes with ie6, and a few other microsoft products) support it.


    DevEdge JavaScript 1.5 Core Reference says it was introduced in JavaScript 1.4.


    MSDN Library Scripting JScript says it was introduced in JScript 1.0 (ie3).
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #12
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Excellent; thanks. I shall have to run some tests ..
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #13
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Well, please notify me of any results you find - I'm interested in how much I can use this.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #14
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I did a couple of different tests - one using implementation, and one using the images collection, like a control.

    The results are mostly what you'd expect, but a couple of surprises in there:


    var DOM = ("implementation" in document);

    * moz (tested ns6.01 and moz1.3b): true
    * netscape 3-4: error
    * opera 7: false ... the first time you view the page in each Opera session, but true on refresh or if you visit it again in the same session
    * opera 4-6: false
    * ie6: true
    * ie4-5: error
    * safari: true


    var DIM = ("images" in document);

    * moz (ditto): true
    * netscape 3-4: error
    * opera 5-7: false
    * opera 4: true!
    * ie6: true
    * ie4-5: error
    * safari: true



    You can see the test page at http://www.brothercake.com/Ref/in.html
    Last edited by brothercake; 03-12-2003 at 12:08 AM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #15
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A couple of things that have come up on further testing:

    - ("implementation" in document) returns true for the mac version of Opera 6; but presumably you can't actually use it.

    - given the strange O7 results, I did another set of tests using (typeof document.implementation). The results are interesting:

    * moz (ns6.01 and moz1.3b): [object DOMImplementation]
    * netscape 3-4: undefined
    * opera 7: [object HTMLDOMImplementation]
    * opera 4-6: undefined .. except:
    * opera 6/mac: [object DOMImplementation] (but presumably you can't actually use it)
    * opera 3: null
    * ie6: [object]
    * ie5/mac: [object Implementation] (?)
    * ie5/win: undefined
    * ie4: undefined
    * safari: [object DOMImplementation]


    What this suggest to me is that, as an object test for DOM1 support, document.implementation has some caveats -

    1 - it's undefined in win/ie5 - which may or may not be appropriate

    2 - it returns an object collection in the mac version of Opera 6, but presumably you can't actually use it.

    3 - it returns null (rather than "undefined") in Opera 3


    Updated test results
    Last edited by brothercake; 03-12-2003 at 11:03 AM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •