Jump to content

[SOLVED] Is there a way of using different DOCTYPEs for different browsers


almightyegg

Recommended Posts

The only way AFAIK to make the pages appear in all browsers is to make sure the CSS and/or HTML is written properly and where IE is concerned, you may have to add a minor "hack" to get it to work at all.

 

You can add this into the HEAD part of your document to load an extra CSS file if IE is used.

<!--[if IE]>
<link rel="stylesheet" type="text/css" href="ie_hack.css" />
<![endif]-->

Link to comment
Share on other sites

It's actually Firefox that's the problem...

 

I have a chatroom script and it uses this code to show the latest posts:

<!-- <textarea id="chatwindow" rows="19" cols="95" readonly></textarea><br>

IE reads it fine in the DOCTYPE that I'v used for the rest of my side.

In FF it displays:

<!-- and then a big white square...

 

Where it's meant to be black and have text in it :S

Link to comment
Share on other sites

// above here is just general tags not to do with this (and the doctype etc..)
<div id="content">
<p id="chatwindow"> </p>
<!-- <textarea id="chatwindow" rows="19" cols="95" readonly></textarea><br>

<input id="chatnick" type="hidden" value="<a href='/player/view.php?id=<? echo "$mem[id]'>$mem[username]</a>"; ?>"> 
<input id="chatmsg" type="text" size="60" maxlength="80"  onkeyup="keyup(event.keyCode);">
<input type="button" value="Post" onclick="submit_msg();"></div>

<br><br><br><br><br>
</div>



<? include 'stats.php'; ?>


</body></html>

<script type="text/javascript">

/* Settings you might want to define */
var waittime=0;		

/* Internal Variables & Stuff */
chatmsg.focus()
document.getElementById("chatwindow").innerHTML = "loading...";
var xmlhttp = false;
var xmlhttp2 = false;


/* Request for Reading the Chat Content */
function ajax_read(url) {
if(window.XMLHttpRequest){
	xmlhttp=new XMLHttpRequest();
	if(xmlhttp.overrideMimeType){
		xmlhttp.overrideMimeType('text/xml');
	}
} else if(window.ActiveXObject){
	try{
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
		try{
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e){
		}
	}
}

if(!xmlhttp) {
	alert('Giving up  Cannot create an XMLHTTP instance');
	return false;
}

xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4) {
	document.getElementById("chatwindow").innerHTML = xmlhttp.responseText;

	zeit = new Date();
	ms = (zeit.getHours() * 24 * 60 * 1000) + (zeit.getMinutes() * 60 * 1000) + (zeit.getSeconds() * 1000) + zeit.getMilliseconds(); 
	intUpdate = setTimeout("ajax_read('chat.txt?x=" + ms + "')", waittime)
	}
}

xmlhttp.open('GET',url,true);
xmlhttp.send(null);
}

/* Request for Writing the Message */
function ajax_write(url){
if(window.XMLHttpRequest){
	xmlhttp2=new XMLHttpRequest();
	if(xmlhttp2.overrideMimeType){
		xmlhttp2.overrideMimeType('text/xml');
	}
} else if(window.ActiveXObject){
	try{
		xmlhttp2=new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
		try{
			xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e){
		}
	}
}

if(!xmlhttp2) {
	alert('Giving up  Cannot create an XMLHTTP instance');
	return false;
}

xmlhttp2.open('GET',url,true);
xmlhttp2.send(null);
}

/* Submit the Message */
function submit_msg(){
nick = document.getElementById("chatnick").value;
msg = document.getElementById("chatmsg").value;

if (nick == "") { 
	check = prompt("please enter username:"); 
	if (check === null) return 0; 
	if (check == "") check = "anonymous"; 
	document.getElementById("chatnick").value = check;
	nick = check;
} 

document.getElementById("chatmsg").value = "";
ajax_write("w.php?m=" + msg + "&n=" + nick);
}

/* Check if Enter is pressed */
function keyup(arg1) { 
if (arg1 == 13) submit_msg(); 
}

/* Start the Requests!  */
var intUpdate = setTimeout("ajax_read('chat.txt')", waittime);

</script>

 

Also, I forgot to mention, they work fine when there's no doctype but my DIVs don't work at all then :S

Link to comment
Share on other sites

Now that's got me stumped! The <!-- is definitely a comment so I'd say that the browser would be sort of ignoring the rest of the file because there's no closing --> but stranger things have been known to occur.

 

Have you got Firebug installed for Firefox? The only thing I can suggest is use that to examine the page in the browser and see how things are being constructed as Firebug will remove anything that isn't valid.

Link to comment
Share on other sites

The <!-- is being used as something else, don't ask me what, it was a premade script...

 

By that link you sent, this should work:

<!-- [if IE]>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<![endif]-->
<!-- [if !IE]>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<![endif]-->

 

Yet IE doesn't work now, FF does

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.