Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-11-2003, 12:33 PM   PM User | #1
KayosIII
New to the CF scene

 
Join Date: Mar 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
KayosIII is an unknown quantity at this point
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
KayosIII is offline   Reply With Quote
Old 03-11-2003, 01:04 PM   PM User | #2
brothercake
Senior Coder


 
Join Date: Jun 2002
Location: near Oswestry
Posts: 4,508
Thanks: 0
Thanked 0 Times in 0 Posts
brothercake is an unknown quantity at this point
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
brothercake is offline   Reply With Quote
Old 03-11-2003, 05:10 PM   PM User | #3
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
try testing for document.implementation
__________________
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

Last edited by liorean; 03-11-2003 at 07:14 PM..
liorean is offline   Reply With Quote
Old 03-11-2003, 05:29 PM   PM User | #4
brothercake
Senior Coder


 
Join Date: Jun 2002
Location: near Oswestry
Posts: 4,508
Thanks: 0
Thanked 0 Times in 0 Posts
brothercake is an unknown quantity at this point
Quote:
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
brothercake is offline   Reply With Quote
Old 03-11-2003, 06:27 PM   PM User | #5
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
Nope! See <http://www.w3.org/TR/1998/REC-DOM-Le...e-binding.html>
__________________
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
liorean is offline   Reply With Quote
Old 03-11-2003, 06:49 PM   PM User | #6
brothercake
Senior Coder


 
Join Date: Jun 2002
Location: near Oswestry
Posts: 4,508
Thanks: 0
Thanked 0 Times in 0 Posts
brothercake is an unknown quantity at this point
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
brothercake is offline   Reply With Quote
Old 03-11-2003, 09:19 PM   PM User | #7
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
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.
__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Old 03-11-2003, 09:21 PM   PM User | #8
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
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');
__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Old 03-11-2003, 09:29 PM   PM User | #9
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
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
liorean is offline   Reply With Quote
Old 03-11-2003, 09:39 PM   PM User | #10
brothercake
Senior Coder


 
Join Date: Jun 2002
Location: near Oswestry
Posts: 4,508
Thanks: 0
Thanked 0 Times in 0 Posts
brothercake is an unknown quantity at this point
Quote:
Originally posted by liorean
var dom1=('implementation' in document)
Hey that's interesting. I didn't realise you could use in like that
__________________
"Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

Last edited by brothercake; 03-11-2003 at 09:49 PM..
brothercake is offline   Reply With Quote
Old 03-11-2003, 10:16 PM   PM User | #11
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
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
liorean is offline   Reply With Quote
Old 03-11-2003, 10:20 PM   PM User | #12
brothercake
Senior Coder


 
Join Date: Jun 2002
Location: near Oswestry
Posts: 4,508
Thanks: 0
Thanked 0 Times in 0 Posts
brothercake is an unknown quantity at this point
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
brothercake is offline   Reply With Quote
Old 03-11-2003, 10:47 PM   PM User | #13
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
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
liorean is offline   Reply With Quote
Old 03-11-2003, 11:00 PM   PM User | #14
brothercake
Senior Coder


 
Join Date: Jun 2002
Location: near Oswestry
Posts: 4,508
Thanks: 0
Thanked 0 Times in 0 Posts
brothercake is an unknown quantity at this point
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
__________________
"Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

Last edited by brothercake; 03-11-2003 at 11:08 PM..
brothercake is offline   Reply With Quote
Old 03-12-2003, 09:59 AM   PM User | #15
brothercake
Senior Coder


 
Join Date: Jun 2002
Location: near Oswestry
Posts: 4,508
Thanks: 0
Thanked 0 Times in 0 Posts
brothercake is an unknown quantity at this point
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
__________________
"Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

Last edited by brothercake; 03-12-2003 at 10:03 AM..
brothercake is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:12 PM.


Advertisement
Log in to turn off these ads.