<textarea name="xxx" style="width:100%" rows="18" wrap="VIRTUAL" id="xxx" onSelect="javascript: storeCaret(this);" onClick="javascript: storeCaret(this);" onKeyDown="editTab()"></textarea>
父窗口中需要用到的JS代码:
function storeCaret (textEl){
if(textEl.createTextRange){
textEl.caretPos = document.selection.createRange().duplicate();
}
}
function insertAtCaret() {
var returnValue = showModalDialog("test.html", window, "dialogWidth:550px;dialogHeight:350px;help:no;scroll:no;status:no");
if (document.formname.xxx.createTextRange && document.formname.xxx.caretPos) {
var caretPos = document.formname.xxx.caretPos;
caretPos.text =caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? returnValue + ' ' : returnValue;
}
else
{
document.formname.xxx.value = returnValue;
}
}
模态窗口test.html中:
function ok()
{
window.returnValue = "\n[codes="+document.getElementById("codetype").value+"]\n"+document.getElementById("codes").value+"\n[/codes]\n";
self.close();
}