...

View Full Version : xbrowser innerHTML issues



Coastal Web
05-21-2005, 03:02 AM
Hola folks, can anyone over look this sample code and explain why it works in IE/opera, but fails in NN, and FireFox? I can't seem to figure it out.



<script>
function show(layer, content){
if(layer){

if(content){
closeButton =

"%3CBR%3E%3CBR%3E%3Ca%20href%3D%22javascript%3Ashow%28%27"+layer+"%27%2C%20%27%27%29%3B%22%3Eclose%3C/a%3E";

fullContent = unescape(content)+unescape(closeButton)+"<BR>----<BR>";
}else{
closeButton = "";
fullContent = "";
}

if(document.layers){
//NN4
document.layers[layer].document.open();
document.layers[layer].document.write(fullContent);
document.layers[layer].document.close();
return;
}

if(document.all){
//IE
document.all[layer].innerHTML = fullContent;
return;
}

if(!document.all && document.getElementById){
//NN6
document.getElementById(content).innerHTML = fullContent;

return;
} } }

</script>

<a href="javascript:show('test',

'%3CTable%20bgcolor%3D%22red%22%20border%3D%2210%22%20height%3D%2250%22%20width%3D%2280%25%22%3E%3CT R%3E%3CTD%20bgcolor%3D%22white%22%3ETEST%20TEST%20TEST%20%2C%20NOTHING%20SPECIAL%20IN%20HERE...%3CBR %3E%3CBR%3E%3CBR%3Etest%20test%20test...%3C/tr%3E%3C/td%3E%3C/table%3E')">show</a>
<BR>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam
erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exercitation ulliam corper suscipit lobortis nisl ut aliquip ex ea commodo
consequat. Duis autem veleum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel willum lunombro dolore eu
feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te
feugait nulla facilisi.
<Br>
<div id="test">
</div>
<br>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam
erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exercitation ulliam corper suscipit lobortis nisl ut aliquip ex ea commodo
consequat. Duis autem veleum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel willum lunombro dolore eu
feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te
feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet
dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exercitation ulliam corper suscipit lobortis nisl ut
aliquip ex ea commodo consequat. Duis autem veleum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel willum
lunombro dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit
augue duis dolore te feugait nulla facilisi.


Thanks for the help!
[note: l'm not sure if whitespace got added in when i cut and pasted this, but l can assure you there's no whitespace on the actual page l'm working with locally]

S. Gram

Coastal Web
05-21-2005, 03:17 AM
found the issue:

if(!document.all && document.getElementById){
//NN6
document.getElementById(content).innerHTML = fullContent;
return;

shoul've been:

if(!document.all && document.getElementById){
//NN6
document.getElementById(layer).innerHTML = fullContent;
return;


thanks anywho.. :D

Kor
05-23-2005, 02:10 PM
to speed a little bit the code (and for obvious logical reasons, as the NS4 and IE4 are used very little these times) I guess that you should have the order of the conditions like this:

if(document.getElementById){//all the modern compliant DOM browsers, including NS6+, IE5+, Opera, Safari, Mozilla....
...
}
else if(document.layers){//NS4 only
...
}
else if(document.all){//IE4 only
...
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum