Welcome to WebmasterWorld Guest from 54.163.168.15

Forum Moderators: open

XHTML interfering with Javascript

Why & how to fix..

   
1:42 pm on May 22, 2002 (gmt 0)

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Have you seen this before? I have a chunk of javascript for a menu which works fine in MSIE (regardless of DOCTYPE as html or xhtml) and works fine in NN6 with DOCTYPE set to html. But set it to xhtml and the menu can't be seen in NN6.

The script is external and is called with:

<script type="text/javascript" language="Javascript">

function Go(){return}

</script>
<script type="text/javascript" src="nsmenu_var.js"></script>
<script type="text/javascript" src="menu_com.js"></script>

The DOCTYPE is:

<!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" xml:lang="en" lang="en">

As always, your guidance is most appreciated.

1:50 pm on May 22, 2002 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Could you post the (x)html?

Nick

2:13 pm on May 22, 2002 (gmt 0)

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Here ya go...

<html>
<head>
<title>title</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="keywords" content="blah blah" />
<meta name="description" content="blah blah" />
<link rel="stylesheet" href="dki.css" type="text/css" />
</head>

<body bgcolor="#FFFFFF" text="#000000">
<script type="text/javascript" language="Javascript">

function Go(){return}

</script>
<script type="text/javascript" src="nsmenu_var.js"></script>
<script type="text/javascript" src="menu_com.js"></script>
<noscript>Your browser does not support script</noscript>
</body>
</html>

I just noticed something - I didn't include the DOCTYPE. When I add this

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

it doesn't work in NN6 (still ok in MSIE though).

2:14 pm on May 22, 2002 (gmt 0)

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Or did you mean the original xhtml document?
2:32 pm on May 22, 2002 (gmt 0)

10+ Year Member



Er, well, try moving the external script links before the function call in the XHTML document, like so.

<script type="text/javascript" src="nsmenu_var.js"></script>
<script type="text/javascript" src="menu_com.js"></script>
<script type="text/javascript" language="Javascript">

function Go(){return}

</script>

Without seeing the originals (XHTML or scripts), I can't think of anything else immediately.

2:47 pm on May 22, 2002 (gmt 0)

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



moonbiter,
I just stickied you the URLs if you have time.
3:47 pm on May 22, 2002 (gmt 0)

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



An update,
I was reading up on DOCTYPE and it lead me to trying this:

I changed the HTML DOCTYPE declaration from HTML 4.01 Transitional//EN to HTML 4.0 Transitional//EN and the menu shows up in NN6 fine. Go figure.

Unfortunately, I don't see a similar solution to the XHTML version.

4:12 pm on May 22, 2002 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



let's see the menu xhtml itself please lorax?

Nick

4:31 pm on May 22, 2002 (gmt 0)

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Hey Nick,
I stickied you the info as well. I've got to take a break from this to get some air - before I completely lose it!
8:05 pm on May 22, 2002 (gmt 0)

10+ Year Member



Okay, not to get your hopes up, but over lunch I took a look at the stuff you stickied me and this is what I found out.

When you put a doctype on menu.htm, the menu is being constructed by the javascript and is actually there. However, for some reason the values for the size and positioning properties (width, height, top, left, etc.) are getting scragged in Mozilla/Netscape.

As a result, when Gecko (the rendering engine) renders the output of the script, the computed style values for size and positioning values are all screwed up (width of 0px or 0.666667px, for example), and the menu isn't visible (although it is there).

As an aside, I noticed in MSIE 6 that the positioning of the submenus is getting also getting hosed when you add a DOCTYPE.

So ... the problem is in the menu_com.js file and the way it is constructing and rendering the menu. Alas, this is a very complex js -- too complex for my small brain to debug in the time I have available. I'd suggest either:

  1. contact the original author
  2. do without the doctype
Sorry I couldn't be of more help.
9:41 pm on May 22, 2002 (gmt 0)

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Moonbiter & Nick,
Thank you both for your efforts. I have emailed the author to alert him to this problem. I know javascript well enough to be dangerous and now that I have a rough idea of what's going on - I'll see if I can find the source while I wait to see if he responds.

BTW moonbiter - I love your profile image!

9:42 pm on May 22, 2002 (gmt 0)

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Whoops - you don't have a profile image - now who was that??
1:54 pm on May 28, 2002 (gmt 0)

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Update
As it turns out I wrote the author of the script and told him about the problem. Upon thinking more about this I realized that the script has to create HTML elements and - as Moonbiter pointed out - these may not be well formed.

The author wrote me back and noted that he agreed and supplied me a link to the updated version in which he had fixed the problem. So... I think the problem may be solved.

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month