Jump to content

IE 6 Problem while using AJAX - Styles/CSS


tinmat

Recommended Posts

Hello,It is about *XMLHttpRequest/ActiveXObject, in IE 6.0:White trying to build pages with dynamic content, I have run myself into a problem. Everything is fine with Firefox, however IE 6.0 won't apply any styles/stylesheet that come within a document. In other words if I am going to import a document into another document, the result of an imported document will be displayed without any styles (even though styles are embeded)! I tried a lot of random ways - but IE 6.0 would always ignore associated styles and display raw data/content.Anyone got an idea how to apply styles towards rotating/dynamic content in IE 6.0? Thanks in advance! :)

function loadXMLDoc(){if (window.XMLHttpRequest)  {// code for IE7+, Firefox, Chrome, Opera, Safari  xmlhttp=new XMLHttpRequest();  }else  {// code for IE6, IE5  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  }xmlhttp.onreadystatechange=function()  {  if (xmlhttp.readyState==4 && xmlhttp.status==200)	{	document.getElementById("display").innerHTML=xmlhttp.responseText;	}  }xmlhttp.open("GET","service.html",true);xmlhttp.send();}// works fine in firefox and does incorporate content as they are/with styles// works in IE 6.0, but does incorporate only the content itself without any styles/css embeded within (just plain raw data)

Link to comment
Share on other sites

hm, oddly enough the styles that come within elements (as for instance <div style="etc.">) will be displayed/applied in IE 6. unfortunately that's not enough, and I really need to find a way how to provide styles in the standard fashion as if they would be coming from the <head></head> section or external file.

Link to comment
Share on other sites

Do I understand correctly that the data in xmlhttp.responseText contains <style> tags? I'm surprised any browser honors them, since that violates the standards. (Actually, most browsers will attempt to honor document errors in some way or another.)Could you simply have the correct style info in the original stylesheet? That might not work if the nature of the incoming data cannot be predicted with any regularity.It should be possible to use DOM methods to add a new style element to your <head> section. I've never tried it, though, and I'm not sure about cross-browser compatibility.

Link to comment
Share on other sites

Do I understand correctly that the data in xmlhttp.responseText contains <style> tags? I'm surprised any browser honors them, since that violates the standards. (Actually, most browsers will attempt to honor document errors in some way or another.)Could you simply have the correct style info in the original stylesheet? That might not work if the nature of the incoming data cannot be predicted with any regularity.It should be possible to use DOM methods to add a new style element to your <head> section. I've never tried it, though, and I'm not sure about cross-browser compatibility.
Deirde,Thanks for referring me to DOM methods against a head element, worked like a charm - more importantly IE 6 likes it (able to switch stylesheets on every ajax call). Although taken some time to work it out cause haven't used anything like it before,:)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...