Log in

View Full Version : DHTML, IE, and DOCTYPE declaration



drg
04-26-2007, 07:02 PM
I haven't found any other threads on this issue in other forums, so my apologies in advance if this is a known issue that I'm not aware of. The following DHTML script, which creates a simple mouse trail, works great in Firefox and IE. However, if I add a DOCTYPE declaration, it does not work in IE, but still works fine in Firefox. Note that I've already tried changing the DOCTYPE version to 1.1, but no luck. Thanks in advance.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Mouse Trail</title>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
</head>
<body onmousemove="moveMouse(event)">
<script type="text/javascript">
/* <![CDATA[ */
var trailInterval = 12;
var yPosition = -10;
var xPosition = -10;
var animationStarted = false;
for (i = 0; i < trailInterval; i++) {
document.write("<div id='dots"+i+"' style='position:absolute;top:-10px;left:-10px;width:"+i/2+"px;height:"+i/2+"px;background:blue;font-size:"+i/2+"px'></div>");
}
function moveMouse(event) {
if (!animationStarted) {
animationStarted = true;
animate();
}
xPosition = event.screenX + 10;
if (navigator.appName == "Microsoft Internet Explorer")
yPosition = event.screenY - 120;
else if (navigator.appName == "Netscape")
yPosition = event.screenY - 65;
}
function animate(){
for (i = 0; i < trailInterval; i++){
var temp1 = document.getElementById("dots"+i);
if (i < trailInterval-1){
var temp2 = document.getElementById("dots"+(i+1));
temp1.style.top = temp2.style.top;
temp1.style.left = temp2.style.left;
}
else {
temp1.style.top = yPosition + "px";
temp1.style.left = xPosition + "px";
}
}
setTimeout("animate()",40);
}
/* ]]> */
</script>
</body>
</html>

boogyman
04-26-2007, 07:30 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Mouse Trail</title>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
</head>


should be



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Mouse Trail</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

Twey
04-26-2007, 07:34 PM
Because IE doesn't support XHTML yet.

I doubt that will help with your problem, though (and you'd also have to revalidate (http://validator-test.w3.org/) a lot of your site).

"Doesn't work" isn't an adequate description of a problem. What exactly goes wrong? What's the error you get?

drg
04-26-2007, 10:10 PM
Thanks for replying so fast. Your suggestions was just to change the XHTML DOCTYPE declaration to an HTML DOCTYPE declaration, which unfortunately didn't do the trick. Let me know if you have any other ideas. Note that the code in my original posting is complete and doesn't require any external image files, so you can test it yourself - if you have nothing else to do ;). Thanks again.

Twey
04-26-2007, 10:13 PM
Certainly we can, but since it's your problem, it's usually considered polite if you provide the information required to fix it :) If you can't for some (good) reason, say so and we'll do it.

drg
04-26-2007, 10:14 PM
I suspect you are right in that IE probably just doesn't adequately support XHTML. But, I am using IE 7, so I'm curious as to why. Note that the code in my original posting is complete and doesn't require any external image files, so you can test it yourself. It should just display a simple mouse trail behind the cursor, but nothing shows up in IE 7 when the file includes the DOCTYPE declaration. I've tried using version 1.1 and transitional, but no lcuk.

drg
04-26-2007, 10:20 PM
Regarding your comment about it usually being considered polite to provide the information required to fix the problem - if I knew what the information was that is required to fix the problem, I wouldn't need to ask this forum, now would I? :)

boxxertrumps
04-26-2007, 10:26 PM
doesn't adequately support XHTML.
Doesn't support at all. MS promised they would, and didn't (no suprise), and so a majority of the web is still error laden with bugs and hacks everywhere... XHTML would have done away with most of this, because as it is a facet of XML it displays errors in the document rather than try to render the page. I have the same problem, so i just send it with an html** content type header so it IE error corrects it into html. i don't reccommend this use, though.
source anyways, if you really want to use it.

<?php
if (
!strstr($_SERVER["HTTP_USER_AGENT"],"MSIE") ||
strstr($_SERVER["HTTP_USER_AGENT"],"like MSIE") ||
strstr($_SERVER["HTTP_USER_AGENT"],"Opera")
) {
header("Content-type: application/xhtml+xml; charset=UTF-8");
echo"<?xml version=\"1.0\"?>";
} else {
header("Content-type: text/html; charset=UTF-8");
$fail = TRUE;
}
error_reporting(E_ALL);
$base = "http://boxxertrumps.bo.funpic.org/";
?>
EDIT: **actually, i just don't send it with an xhtml contype, sorry to confuse if you are.
EDIT2: needed to send as UTF-8, b/c default is an ISO one i changed the code.

Twey
04-26-2007, 11:03 PM
EDIT: **actually, i just don't send it with an xhtml contype, sorry to confuse if you are.No, you do send it with an HTML content type. If you don't specify one, the PHP parser will use text/html automatically. However, as I said above, I don't think the DOCTYPE is the cause of the problem here.
Regarding your comment about it usually being considered polite to provide the information required to fix the problem - if I knew what the information was that is required to fix the problem, I wouldn't need to ask this forum, now would I? :)As I've said above, you can tell us what the error is you get, how exactly it fails to work, and possibly other things.

boxxertrumps
04-26-2007, 11:49 PM
Twey, I meant "I" as in, i didn't actively put the content type header in.
I looked in Konqueror's document information window, and saw that instead of a UTF charset it was an ISO.
fixed the code to send as text/html;UTF-8...

drg
04-27-2007, 02:40 AM
My apologies, but I thought my initial posting clearly described the issue. As I mentioned, the DHTML script creates a simple mouse trail and works fine in Firefox 2 and IE 7. However, if I add a strict XHTML DOCTYPE declaration, it does not work in IE, but does work in Firefox. I don't receive any error messages and the page validates successfully as XHTML Strict.

drg
04-27-2007, 02:59 AM
Twey, I meant "I" as in, i didn't actively put the content type header in.
I looked in Konqueror's document information window, and saw that instead of a UTF charset it was an ISO.
fixed the code to send as text/html;UTF-8...
The HTML and JavaScript validate successfully. The page doesn't contain a style sheet, so I can't validate the CSS.

I'd really like to avoid IE altogether, but the script is for a textbook on JavaScript and I need to make sure the code works in both Firefox and IE. I need to avoid the content-type hack, but I think it's clever!

Twey
04-27-2007, 09:02 AM
Even using server-side detection to serve IE a special content type is a very ugly hack, and completely removes any advantage to using XHTML (since you can't use any of XHTML's features because it'll then break when served as HTML). Nevertheless, this is irrelevant; the problem is almost certainly caused by IE going into Standards mode, which it does for an XHTML DOCTYPE despite the extensive error-correction required, so it will almost certainly persist with an HTML Strict DOCTYPE.
it does not work in IE ... I don't receive any error messagesThen how do you know it isn't working? The trail does not appear? There's no reason I can see for it to not appear and yet throw no error. I think we should probably wait for someone with IE to give a second opinion here.