[Javascript] Read/write html tag contents with Netscape

Paul javascriptlist at dandemutande.org
Thu Jul 31 21:28:42 CDT 2003


Thanks, Andrew.  Unfortunately, I haven't been able to get your method to
work with Netscape 4.  This is as far as I've gotten; it works with IE 6 &
Netscape 6 but fails on Netscape 4.7:

<p id="Bob">Old contents</p>

<input type="button" value="Change text" onClick="ChangeText('Bob');">

<script language="Javascript"><!--

function ChangeText(argTagName){
var W3C = (document.getElementById) ? 1 : 0; 
var IE4 = (document.all) ? 1 : 0; 
var NS4 = (document.layers) ? 1 : 0; 
	if (W3C) {
		document.getElementById(argTagName).innerHTML = "W3C";
	} else if (IE4) { 
		document.all.item(argTagName).innerText = "IE4";
	} else if (NS4) { 
		// stab in the dark!
		document.layers[argTagName].document.open();
		document.layers[argTagName].document.write("NS4");
		document.layers[argTagName].document.close();
	} else { 
		alert("Don't recognize this browser");
	}
}
--></script>

Is there something wrong with the syntax
"document.layers[argTagName].document"?

What technique can I use with Netscape 4?

Thanks! 
Paul




At 11:09 AM 8/1/2003 +1200, you wrote:
>So far as I know document.getElementById(tagName).innerHTML  would work, but
>not .innerText in Netscape....
>
>Andrew Gibson
>
>----- Original Message -----
>From: Paul
>To: javascript at LaTech.edu
>Sent: Friday, August 01, 2003 11:04 AM
>Subject: [Javascript] Read/write html tag contents with Netscape
>
>
>I need to read & write the text contained by named html tags.
>
>With recent Internet Explorers one can use innerText, i.e.:
>
><td name="Tag4">The desired text to read & write</td>
>...
>function ReadWriteText(argTagName){
>alert(argTagName + ' contains ' + document.all.item(argTagName).innerText);
>document.all.item(argTagName).innerText = "New contents";
>}
>
>How can I do this with Netscape? Is there more than one method, depending
>on Netscape/Javscript version?
>
>Thanks!
>Paul
>
>
>_______________________________________________
>Javascript mailing list
>Javascript at LaTech.edu
>https://lists.LaTech.edu/mailman/listinfo/javascript
>



More information about the Javascript mailing list