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 07-24-2003, 06:35 PM   PM User | #1
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
How can I detect XHTML in the XML DOM? Is that even what I want?

For a script where it detects, and uses appropriate methods, so that it works on XHTML pages regardless of which DOM it's in.

At the moment, I'm testing for document.createElementNS and document.styleSheets, but it's messy - Safari declares support for both but the DOM 2 CSS doesn't actually work ... IE supports document.styleSheets but it uses a proprietary rule syntax ... Opera 7 doesn't support that but it does support createElementNS.

So instead of testing for support with named-browser exclusions, I thought maybe test for the XML DOM ... but then is it safe to assume that any JS-capable browser which is in the XML DOM supports the required methods?

Or is this all bunk ... should I just be pragmatic and test for Gecko ..?
__________________
"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; 07-24-2003 at 06:41 PM..
brothercake is offline   Reply With Quote
Old 07-24-2003, 08:24 PM   PM User | #2
Vladdy
Senior Coder

 
Join Date: Jun 2002
Location: Nashua, NH
Posts: 1,724
Thanks: 0
Thanked 0 Times in 0 Posts
Vladdy is an unknown quantity at this point
Why not just test for method/property you are interested in?
__________________
Vladdy | KL
"Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"
Vladdy is offline   Reply With Quote
Old 07-25-2003, 04:34 PM   PM User | #3
beetle
Senior Coder

 
Join Date: Aug 2002
Posts: 3,467
Thanks: 0
Thanked 0 Times in 0 Posts
beetle has a little shameless behaviour in the past
Agreed, that's how I handle createElementNS
Code:
document.createHTMLElement = function( elemName, attribs )
{
    if ( document.createElementNS )
    {
        var elem = document.createElementNS( "http://www.w3.org/1999/xhtml", elemName );
        var isNamespaced = true;
    }
    else
    {
        var elem = document.createElement( elemName );
        var isNamespaced = false;
    }
    if ( typeof attribs != 'undefined' )
    {
        for ( var i in attribs )
        {
            switch ( true )
            {
                case ( i == 'text' )  : elem.appendChild( document.createTextNode( attribs[i] ) ); break;
                case ( i == 'class' ) : elem.className = attribs[i]; break;
                default : 
                    if ( isNamespaced )
                    {
                        elem.setAttributeNS( "http://www.w3.org/1999/xhtml", i, '' );
                    }
                    else
                    {
                        elem.setAttribute( i, '' );
                    }
                    elem[i] = attribs[i];
            }
        }
    }
    return elem;    
}
__________________
My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
“Minds are like parachutes. They don't work unless they are open”
“Maturity is simply knowing when to not be immature”
beetle is offline   Reply With Quote
Old 07-25-2003, 11:57 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
Yeah that's essentially what I'm doing now, but to save code in disparate places where one or the other method is needed, I wanted to set a global flag that means it understands both document.styleSheets and createElementNS

What I'm currently do is this, and it works just fine:
Code:
udm.safari = (
	navigator.vendor!='KDE'&&
	typeof document.childNodes!="undefined"&&
	typeof document.all=="undefined"&&
	typeof navigator.taintEnabled=="undefined"
	)?true:false;
udm.xdom = (
	typeof document.createElementNS!='undefined'&&
	typeof document.styleSheets!="undefined"&&
	!udm.safari
	)?true:false;
But it's not 100% reliable - because the Safari test is a hack that may not always work - and it doesn't allow for the possibility of future browsers which may, like Safari, declare support for both but not actually have a useable implementation.

So I was thinking, if I *know* a document is in the XML DOM, it's near-as-dammit safe to assume it can support these methods.

But thanks guys for your answers. I wouldn't mind knowing academically how to detect the DOM, but I guess it's not essential to know..
__________________
"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; 07-26-2003 at 08:36 PM..
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 11:39 PM.


Advertisement
Log in to turn off these ads.