Results 1 to 21 of 21

Thread: JavaScript - why is this not Mozilla compatible?

  1. #1

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090

    JavaScript - why is this not Mozilla compatible?

    I have a fairly long script which basically makes a menu. I wanted it like this as it is really easy for me to add more items to it. you can see it at:
    http://acid.freewebpage.org

    Now, why does it only work on IE?
    Here's the code:
    Code:
    <%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
    <html>
    <head>
    <title>Acidic Library - Home</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script src="menu.js"></script>
    <script language="JavaScript">
    if (navigator.appName != "Microsoft Internet Explorer")
    	{
    	alert("sorry, but so far this site is only Internet Explorer compatible. I'm trying to fix this.")
    	}
    function make_menu() {
    var gmenu = document.getElementById('linksmenu')
    gmenu.innerHTML = "<table><tr>"
    for (i=0; i<main_list.length; i++)
    	{
    	gmenu.innerHTML += "<td><br><br><span id='" + main_list[i][0] + "' onClick='sub_menu(this.id)' STYLE='cursor: pointer'>" + main_list[i][0] + "</span></td>"
    	}
    gmenu.innerHTML += "</tr></table>"
    }
    
    function sub_menu(id) {
    for (i=0; i<main_list.length; i++)
    	{
    	if (id == main_list[i][0])
    		{
    		if (main_list[i][0] != document.getElementById(id).innerHTML) //Submenu is already open
    			{
    			document.getElementById(id).innerHTML = main_list[i][0]
    			}
    		else
    			{
    			if (main_list[i][1] == 0) //If menu item goes to URL, not opens submenu
    				{
    				document.location = main_list[i][2]
    				}
    			else //If menu item opens submenu
    				{
    				var mmenu = document.getElementById(id)
    				mmenu.innerHTML = "<td><i><span id='" + main_list[i][0] + "' onClick='sub_menu(this.id)' STYLE='cursor: pointer'><br>" + main_list[i][0] + "</i></span></b><br><br></td>"
    				for (j=0; j<eval(id).length; j++)
    					{
    					mmenu.innerHTML += "<a href='" + main_list[i][2] + "" + eval(id)[j][1] + "'>" + eval(id)[j][0] + "</a><br>"
    					}
    				}
    			}
    		}
    	}
    }
    </script>
    </head>
    
    <body background="background.jpg" bgproperties="fixed" onLoad="make_menu()">
    <table width="80%" border="5" align="center" cellpadding="0" cellspacing="20" bordercolor="#7979FF" bgcolor="#E6E6FF">
      <tr>
        <td width="28%"> 
    <p><b><b></b><span id="linksmenu">Generating List...</span></b></p></td>
        <td width="72%"> <p>Hi and welcome to the most boring part of the site. On 
            the left you have the list of all my script. If you have any construcive 
            comments or want to contribute to this website, please feel free to contact 
            me.
    <hr>
          <p><br>
            <strong>News:<br>
            </strong>15/11/03<br>
            Made the pointer cursor show on the menu. Started making VB application 
            that you can download and browse through the scripts. Realised that this 
            will take time.</p>
          <p>12/11/03<br>
            Adding JavaScripts to the list, getting very bored of it. Made the JScript.html 
            page. Put page on-line</p>
          <p><Br>
            10/11/03<br>
            Started making the site.<br>
            Got the menu sorted, adding things to it.</p>
          </td>
      </tr>
    </table>
    <p>&nbsp;</p>
    </body>
    </html>

    here's the menu.js file:
    Code:
    //List to go into the menu
    main_list = new Array()
    main_list[0] = ["Home","0","index.html"]
    main_list[1] = ["JavaScript","1","http://acid.freewebpage.org/JScript.html?"]
    main_list[2] = ["Contact","0","contact.html"]
    main_list[3] = ["Links","1","http://"]
    
    JavaScript = new Array()
    JavaScript[0] = ["Bubble Sort","0001"]
    JavaScript[1] = ["Temperature Conversion","0002"]
    JavaScript[2] = ["Matrix","0003"]
    JavaScript[3] = ["BBC news","0004"]
    JavaScript[4] = ["Changing cell data","0005"]
    JavaScript[5] = ["Opacity","0006"]
    JavaScript[6] = ["Cookies","0007"]
    JavaScript[7] = ["Scrolling news","0008"]
    
    Links = new Array()
    Links[0] = ["JS-World","www.js-x.com"]
    Links[1] = ["HTML Goodies","www.htmlgoodies.com"]

    P.S. can I specify the code type for HTML/JavaScript as you can with VB?
    Last edited by Acidic; Nov 16th, 2003 at 08:06 AM.
    Have I helped you? Please Rate my posts.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The alert box is extremly annoying.

    Except that a clicked menu jumps down somewhat, it works in Mozilla. Why it jumps down I don't know, and the innerHTML stuff is too tiresome for me sort out.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    the alert box is only temporary, I use Mozilla FireBird, this makes the sub-menus not appear at all. Submenus should appesr when you click on Links or JavaScript.

    edit: Actuall the submenu does appear when you click JavaScript, but not Links.

    Also the table layout goes wierd, in IE the menu is vertical in Firebird it is horizontal.
    Have I helped you? Please Rate my posts.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    And what do you mean by that last question? The <%@ stuff at the top shows up if you mean that. It's only for ASP, you must remove it in static pages.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    <%@ stuff at the top shows up if you mean that. It's only for ASP, you must remove it in static pages.
    Sorry, will get rid of it, Dreamweaver auto inserts it.

    with my last question I meant, in these forums, can you specify the code type so it colour codes JS or HTML correctly?
    Have I helped you? Please Rate my posts.

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    This stuff is seriously messed up...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    No, you can't. You can use [php] for code that uses C-like syntax, but it doesn't work too well.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    i think I can get it working if you can help sort out why the tables don't work. Why in Firebird are the tables horizontal, it must be to do with the function "make_menu()"

    The menu should be vertical.
    Have I helped you? Please Rate my posts.

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Maybe Firebird doesn't like your habit of not finishing statements with semicolons. You should put ; after every statement in JavaScript. You don't need to, but it is a good idea.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  10. #10

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    This stuff is seriously messed up...
    But if I get this working, then It'll be great as it is sooo easy to add more menu items .
    Have I helped you? Please Rate my posts.

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I also noticed that the DOM inspector shows an incorrect tree, and I think I know why.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  12. #12

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    the ; did nothing. where is the tree structure wrong? Plz note that most of it is build dynamically though, DOM inspectors might not see that.
    Have I helped you? Please Rate my posts.

  13. #13
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    eval(id) also is likely not to work cross-browser.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  14. #14

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    eval(id) also is likely not to work cross-browser.
    well it seem to be working.

    Its only the table thing doesn't

    And the JScript.html page:
    it doesn't load up only thing into the Iframe.
    Have I helped you? Please Rate my posts.

  15. #15
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The DOM inspector sees dynamic changes.

    I have no idea why I'm helping you with this, I hate pages where the menu is generated onload with JavaScript.

    Anyway, I've cleaned your code somewhat, that should fix the DOM issue.
    Code:
    function make_menu()
    {
    	var gmenu = document.getElementById('linksmenu');
    	var newHTML = "<table><tr>";
    	for (i=0; i<main_list.length; i++) {
    		newHTML += "<td><br><br><span id='" + main_list[i][0] + "' onClick='sub_menu(this.id)' STYLE='cursor: pointer'>" + main_list[i][0] + "</span></td>";
    	}
    	newHTML += "</tr></table>";
    	gmenu.innerHTML = newHTML;
    }
    
    function sub_menu(id)
    {
    	for (i=0; i<main_list.length; i++) {
    		if (id == main_list[i][0]) {
    			if (main_list[i][0] != document.getElementById(id).innerHTML) { //Submenu is already open
    				document.getElementById(id).innerHTML = main_list[i][0];
    			} else if (main_list[i][1] == 0) { //If menu item goes to URL, not opens submenu
    					document.location = main_list[i][2];
    			} else { //If menu item opens submenu
    				var mmenu = document.getElementById(id);
    				var newHTML = "<td><i><span id='" + main_list[i][0] + "' onClick='sub_menu(this.id)' STYLE='cursor: pointer'><br>" + main_list[i][0] + "</i></span></b><br><br></td>";
    				for (j=0; j<eval(id).length; j++) {
    					newHTML += "<a href='" + main_list[i][2] + "" + eval(id)[j][1] + "'>" + eval(id)[j][0] + "</a><br>";
    				}
    				mmenu.innerHTML = newHTML;
    			}
    		}
    	}
    }
    Of course, your DOM tree is already messed up by your provider with its useless anti-hide-banner end tags.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  16. #16

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    is document.location not supported in FireBird???

    thats what must be wrong with JScript.html
    Have I helped you? Please Rate my posts.

  17. #17
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I think it should be location.href
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  18. #18
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Another thing is this: getElementById is incorrectly implemented in IE to retrieve elements that have only the name attribute set. For Mozilla/Firebird to work you must set the id attribute, preferably to the same value.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  19. #19

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    I got the tables sorted, I didn't even need span, just <br> and <span>
    Have I helped you? Please Rate my posts.

  20. #20

    Thread Starter
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    got it all sorted now, thx
    Have I helped you? Please Rate my posts.

  21. #21
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    Hmm

    As a followup - you should do some CSS on your page, for textformatting etc., would really spice it up. And make spaces between the text and the borders - gives it a better touch.
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

Posting Permissions

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



Click Here to Expand Forum to Full Width