Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"contenteditable" 1

Status
Not open for further replies.

stranger123

Programmer
Apr 16, 2006
76
0
0
GB
Hi,

I want to use <DIV contenteditable> for a editable erea for IE65.5-IE6. For the browsers not support "contenteditable", I want to use <textarea>.
How can I detect when "contenteditable" will be supported and show <DIV>, or not supported and show <TextArea>?

Thank you in advance.
 
This should do the trick.
Code:
<html>

<script type="text/JavaScript">
<!--//
function IECheck(){
	//Detect IE6++
	var version = 0;

	if (navigator.appVersion.indexOf("MSIE")!= -1){
		var temp = navigator.appVersion.split("MSIE")
		version = parseFloat(temp[1]);
	}

	if (version >= 6.0) {
		document.getElementById("textarea").style.display = "none";
		document.getElementById("editable").style.display = "block";
	}
	else {
		document.getElementById("editable").style.display = "none";
		document.getElementById("textarea").style.display = "block";
	}
}
//-->
</script>
</head>
<body onLoad="IECheck()">

<div id="editable">
	<div contenteditable>
		Content
	</div>
</div>

<div id="textarea">
	<textarea>
		Content
	</textarea>
</div>

</body>
</html>

M. Brooks
 
Thank you very much!
One thing not very clear: did your code covering the cases of FireFox or any other non-IE browser?
 
mbrooks said:
Since "contenteditable" is an IE only attribute

Er... except both Safari and Firefox support it, too, AFAIK... and probably other browsers, too.

Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top