Idontwantspam Posted March 31, 2007 Share Posted March 31, 2007 Hi,I am trying to use something like this, and it all works just fine until I add a doctype. I usually use XHTML 1.0 transitional, but this wouldn't work with HTML 4 or XHTML 1. Any idea how I can make this work with a valid doctype? I would just skip the doctype, but then the page won't validate... Link to comment Share on other sites More sharing options...
sdageforde Posted March 31, 2007 Share Posted March 31, 2007 Have you tried forcing the browser into quirks mode first?Add <?xml version="1.0" encoding="iso-8859-1"?> before the doctype statement. Link to comment Share on other sites More sharing options...
ripken204 Posted April 1, 2007 Share Posted April 1, 2007 just wondering, why exactly do you care? i used to care, thinking that it would make the page better, but it doesnt. its just extra coding that serves no real purpose. and its pain in the a** to get everything to validate correctly. Link to comment Share on other sites More sharing options...
Idontwantspam Posted April 2, 2007 Author Share Posted April 2, 2007 Have you tried forcing the browser into quirks mode first?Add <?xml version="1.0" encoding="iso-8859-1"?> before the doctype statement.This is what I have before <html>:<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">I tried changing <?xml version="1.0" encoding="UTF-8"?>to<?xml version="1.0" encoding="iso-8859-1"?>but it still didn't work... I suppose I could just forget the whole validation/doctype thing for that page, but I don't really want to... Link to comment Share on other sites More sharing options...
CoffeeFiend Posted April 2, 2007 Share Posted April 2, 2007 I only wish they were all this easy As for quirksmode, you really don't want that. And I see no excuse for not having a proper doctype. Without a doctype your stuff gets rendered in quirksmode, doesn't use standard DOM (like what you're seeing here). Using a doctype, the browsers know how to render it properly (display properly in more browsers consistently), it's actually faster, and it's just more standards compliant in general. Not using one is sloppy at best. I see no reason to use "iso-8859-1" instead of UTF-8 either (UTF-8 is unicode and supports more languages).Their sloppy coding only worked in the first place because the browser is in quirksmode: it tries to make sense out of the junk you feed it... guessing stuff where you don't provide it.Long story short, you're trying to set the position of the image using .top & .left, but they fail at providing a unit! Likely you mean pixels, but there's no real reason to go guessing units for everything... You could use percentages if you wanted to (not so practical in this case, but that's besides the point). Just add +'px' to the 2 lines to tell it you actually mean pixels, and it'll work just fine:<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml"><head><script type="text/javascript">function cursor(event){document.getElementById('trail').style.visibility="visible"document.getElementById('trail').style.position="absolute"document.getElementById('trail').style.left=event.clientX+10+'px'document.getElementById('trail').style.top=event.clientY+'px'}</script></head><body onmousemove="cursor(event)"><h1>Move the cursor over this page</h1><img id="trail" style="visibility:hidden" src="w3schools.gif" width="100" height="30"></body></html>Quickly tested OK in FF 2 and IE7. Link to comment Share on other sites More sharing options...
Idontwantspam Posted April 2, 2007 Author Share Posted April 2, 2007 It does seem to work! Thank you thank you thank you! Maybe it didn't for you, but it did for me, in Firefox, IE 6 and Opera. Thank you thank you. Stupid me, I forgot the darn units. Should have known that. Thanks again. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now