SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    File opens ok in IE6 but not FF

    Why does this file
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
    
    <title>XML Based Menu</title>
    
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    
    <script type="text/javascript" src="sarissa/sarissa.js"></script>
    
    <script type="text/javascript">
    
    function initMenu(xmlFile) {
    
    	var xml = Sarissa.getDomDocument();
    
    	xml.async = false;
    
    	xml.load(xmlFile);
    
    
    	var nodes = xml.documentElement.childNodes;
    
    	for (var i = 0; i <= nodes.length - 1; i++) {
    
    		if (nodes.item(i).nodeType != Node.ELEMENT_NODE) continue;
    
    		var output = '<a href="' + nodes.item(i).getAttribute('target') + '">' +
    
    			nodes.item(i).getAttribute('label') + '</a><br />';
    
    		document.write(output);
    
    	}
    
    }
    
    </script>
    
    </head>
    
    
    
    <body>
    
    <h1>My Menu</h1>
    
    <script type="text/javascript">
    alert("hi");
    
    initMenu('navmenu.xml');
    
    </script>
    
    </body>
    
    </html>
    open ok in IE6 but not FF

  2. #2
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're using an XHTML DTD so document.write won't work (http://www.w3.org/MarkUp/2004/xhtml-faq#docwrite), and you have characters within your script element which could be mistaken for HTML elements by less capable browsers ('<'/'>'). I suggest keeping your JS in a seperate file or wrapping your code like this:

    Code html4strict:
    <script type="text/javascript">
    // <![CDATA[
     
        [JavaScript code here]
     
    // ]]>
    </script>

    To add text to an XHTML document you should do it via the DOM:

    Code JavaScript:
    var text = document.createTextNode('Some text...');
    var p = document.createElement('p');
    p.appendChild(text);
    document.appendChild(p);
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  3. #3
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,255
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    I used this for the xml file
    Code XML:
    <?xml version="1.0" ?>
    <navmenu>
    <item target="target1" label="label1"/>
    <item target="target2" label="label2"/>
    <item target="target3" label="label3"/>
    </navmenu>
    I don't know what the node names are, or how they look, but make sure they have the target and label attributes.

    It worked for me in both IE6 and Firefox 2, but the page was served as "text/html", i.e. "fake XHTML", so that may be why it worked OK for me using Firefox.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,869
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Well it would have to be served as HTML in IE since IE doesn't understand XHTML at all.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Enthusiast
    Join Date
    Sep 2007
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It was a Firefox bug
    http://www.nabble.com/Permission-den...d19449024.html

    Installed 3.0.2 and everything works fine

  6. #6
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Regardless of what the actual error is the practices I mentioned are still worth taking on board.
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)


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
  •