...

View Full Version : Doctype "breaks" javascript?



kaitco
12-09-2006, 09:08 PM
What troubleshooting measures can I take when a script seems to break if a proper Doctype is used?

For example (http://www.dynamicdrive.com/forums/showthread.php?t=15535), if I use a game script precisely as it is offered, it works perfectly, sans Doctype, like here (http://www.doriennesmith.com/peace/hanoi2.html). However, if I add a doctype to the page, like here (http://www.doriennesmith.com/peace/hanoi.html), the script no longer works correctly. The problem also persists across browsers.

So, I am wondering what, if anything, I can do to ensure that a script works correctly with a Doctype, even if it was created without one?

Many thanks!

david_kw
12-09-2006, 10:16 PM
That's a wild one. It appears that when you add the DOCTYPE it makes clientHeight go to zero in IE7 and FF1.5 and FF2. Interestingly it works in IE6. Go figure.

So what is happening in the code is as soon as you move the piece the code decides you are outside the client window (since the mouse y is greater than the client height which it thinks is zero). So it immediately drops it back on the stack.

So I found this link

http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html

Maybe you can pull something out of there to fix it. Either that or get rid of the check in dragDisk() that is around 190 that drops the disk if it leaves the screen.

david_kw

david_kw
12-09-2006, 10:34 PM
That site seems to suggest when you have DOCTYPE that you have to start checking

document.documentElement.clientHeight

instead of

document.body.clientHeight

david_kw

kaitco
12-10-2006, 02:18 AM
Thanks a lot!

VR2
12-11-2006, 12:33 AM
Yeah the DOCTYPE declaration has IE move to "standards Mode" instead of "Quirks Mode" and it moves alot of stuff, especially from body, to documentElement.

One thing I was never able to get (my head) around though was that when using a DOCTYPE, the body tag could specify no scroll (bars) like this


<body scroll=no>

But there seems to be no way in code to do the same thing (turn off scrollbars for a document after the page is loaded).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum