SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Cross Browser Help

    After 1.5 years of writting my website I installed NS. It's JS works alot different to IE's, so it looks like I've got to write most of my site again!! [img]images/smilies/frown.gif[/img]

    NS will only read 1 external JS file, which is abit of a nuisance as my site has a JS file common to site, another for the subfolders of the site, and the page's JS included with the HTML.

    I'm trying to put all of common functions into one JS, but some of the functions have large amounts of text assigned to them. I'm trying to import the text using XML sheets as needed, but having a bit of a problem with the line
    Code:
    xmlDoc.childNodes[i].childNodes[2]
    where NS will only read 1 array of childNodes. How do extract xml with NS's JS?
    Last edited by Markdidj; Jul 5, 2003 at 00:16.
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  2. #2
    SitePoint Member
    Join Date
    Feb 2003
    Location
    UK
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    NS will only read 1 external JS file
    all the versions of Netscape browser from 4, 6, 7 to Mozilla/Phoenix can read in as many external JavaScript files as you want - there's no limit to 1....

    As you're talking about the DOM I assume you're talking about N6+ browsers

    I've just done a test in Mozilla - no problems with this:

    Code:
    var xmlDoc;
    if (document.implementation && document.implementation.createDocument)
    	{
    		xmlDoc = document.implementation.createDocument("", "", null);
    		xmlDoc.onload = foo;
    		xmlDoc.load("test.xml");
    	}
    	
    
    function foo(){
    	var o = xmlDoc.childNodes[0].childNodes[2];
    	for (i in o) alert(i + "  =  " + o[i])
    }

  3. #3
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks Piglet;
    Just tried the ext JS and it works fine. That was weird.
    Well, I don't have to re-write my whole site. I'm glad I wrote in here before doing so!!!
    I'll try the other now.
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  4. #4
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That was really useful for netscape; thanks. Didn't do a thing in IE though, no alerts at all....
    Code:
    <menu>
    <menu1>
    <index>index</index>
    <origins>origins</origins>
    </menu1>
    </menu>
    thats my basic xml, but when I use
    Code:
     
    alert(Xtitle=xmlDoc.childNodes[0].nodeName)
    alert(Xsub1=xmlDoc.childNodes[0].childNodes[0].nodeName)
    in IE Xtitle="menu" & Xsub1="menu1" but in NS I get
    Xtitle="menu" & Xsub1="#text". Why does the "#text" come up in NS when IE reads it and how do I rectify it?
    Thanks in advance.
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  5. #5
    SitePoint Guru bronze trophy blufive's Avatar
    Join Date
    Mar 2002
    Location
    Manchester, UK
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First, I am not an XML guru. however, here goes:

    I think IE is (incorrectly) ignoring your whitespace, and Netscape isn't. Here's your code again, but I'm showing the whitespace:
    Code:
    <menu>[line-end]
    <menu1>[line-end]
    <index>index</index>[line-end]
    <origins>origins</origins>[line-end]
    </menu1>[line-end]
    </menu>
    Menu1 has not two children, but five - [whitespace], index, [whitespace], origins and another [whitespace]. Those whitespaces are being ignored by IE, but in XML, whitespace is supposed to be significant, and Netscape is including them as #text nodes.

    From the fact that you see menu1 as the first child of menu, I would also guess that your actual code is laid out like this:
    Code:
    <menu><menu1>[line-end]
    <index>index</index>[line-end]
    <origins>origins</origins>[line-end]
    [etc.]
    If I'm right, you should probably try using getElementById or getElementsByTagName instead of just grabbing them out of the array by index.

  6. #6
    SitePoint Member
    Join Date
    Feb 2003
    Location
    UK
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The script I posted was Mozilla only - for a good discussion on cross-browser XML, this link is a good start

    As to the previous post - I'd second that opinion (all of it) - the #text nodes are 'correct' but get in the way and need filtering out if you want to process the logical structure of the XML rather than the physical structure.


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
  •