homepage Welcome to WebmasterWorld Guest from 54.163.72.86
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
XHTML interfering with Javascript
Why & how to fix..
lorax




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

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.

 

Nick_W




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

Could you post the (x)html?

Nick

lorax




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

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).

lorax




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

Or did you mean the original xhtml document?

moonbiter




msg:1476984
 2:32 pm on May 22, 2002 (gmt 0)

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.

lorax




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

moonbiter,
I just stickied you the URLs if you have time.

lorax




msg:1476986
 3:47 pm on May 22, 2002 (gmt 0)

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.

Nick_W




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

let's see the menu xhtml itself please lorax?

Nick

lorax




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

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!

moonbiter




msg:1476989
 8:05 pm on May 22, 2002 (gmt 0)

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.
lorax




msg:1476990
 9:41 pm on May 22, 2002 (gmt 0)

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!

lorax




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

Whoops - you don't have a profile image - now who was that??

lorax




msg:1476992
 1:54 pm on May 28, 2002 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved