si je set, pour une div, isContentEditable à true :
- ça ne marche pas si activé dans window.onload (do_it());
- ça marche si activé par un bouton (toggleEdit()).
Pourquoi ?
Le code :
------------------------------------------------------------------------
<html>
<head>
<!-- see
https://developer.mozilla.org/en/DOM/element.onpaste -->
<title>onpaste event example</title>
<style type="text/css">
.normal {color: black}
.editing {color: red}
</style>
<script type="text/javascript">
window.onload=do_it;
var editor;
var editBtn;
function do_it(){
editor=document.getElementById("editor");
editBtn=document.getElementById("editBtn");
log("editor.isContentEditable = "+editor.isContentEditable);
editor.isContentEditable=true;
log("editor.isContentEditable = "+editor.isContentEditable);
editor.className = (editor.isContentEditable) ? "editing" :
"normal";
editor.addEventListener("paste", pasteIntercept, false);
}
function toggleEdit(){
log("editor.isContentEditable = "+editor.isContentEditable);
var newState = !editor.isContentEditable;
editor.contentEditable = newState;
log("editor.isContentEditable = "+editor.isContentEditable);
editor.className = (newState) ? "editing" : "normal";
editBtn.innerHTML = (newState) ? "Disable Editing" : "Enable
Editing";
}
function log(txt){
document.getElementById("log").appendChild(document.createTextNode(txt +
"\n"));
}
function pasteIntercept(e){
document.getElementById("result").innerHTML=document.getElementById("edi
tor").innerHTML;
log("Pasting!");
}
</script>
</head>
<body>
<h3>Play with this editor!</h3>
<p><p>Some text to paste</p></p>
<div id="editor">
Try pasting text into this area!<br />
...<br />
end<br />
</div>
<p><button id="editBtn" onClick="toggleEdit()"
onFocus="this.blur()">Enable Editing</button></p>
<h3>Log</h3>
<textarea rows="15" cols="80" id="log" readonly="true"></textarea>
<h3>Result</h3>
<div id="result"></div>
</body>
</html>
------------------------------------------------------------------------
--
« Là où la vérité n'est pas libre,
la liberté n'est pas vraie. »
(Jacques Prévert)