C
Ciaran
Hi, I'm working on a WYSIWYG editor and I've run into some difficulty
trying to select a range in chrome. I believe the problem is the same
as mentioned here: http://www.google.com/support/forum/p/Chrome/thread?tid=1ca7b96da3e71324&hl=en
but none of the solutions listed seem to work for me - I just keep
getting errors.
Here's my code:
The idea is that it finds the tag with the ID "caret", selects it and
deletes it, leaving the caret (text cursor) in its position. It works
like a charm in Firefox but chrome alerts null as the selection object
rather than [object HTMLBodyElement] like FF. I only need support for
FF & chrome so IE is not an issue (thank god!)
function resetCaret(iframename){
iframe=document.getElementById(iframename).contentWindow
referenceNode = iframe.document.getElementById("caret");
if(referenceNode){
sel=iframe.getSelection()
alert(sel.focusNode)
range=sel.getRangeAt(0);
range.selectNode(referenceNode);
range.deleteContents();
}
}
Thanks for any help - this has been going on a long while now and it'd
be great to get it behind me!
Ciarán
trying to select a range in chrome. I believe the problem is the same
as mentioned here: http://www.google.com/support/forum/p/Chrome/thread?tid=1ca7b96da3e71324&hl=en
but none of the solutions listed seem to work for me - I just keep
getting errors.
Here's my code:
The idea is that it finds the tag with the ID "caret", selects it and
deletes it, leaving the caret (text cursor) in its position. It works
like a charm in Firefox but chrome alerts null as the selection object
rather than [object HTMLBodyElement] like FF. I only need support for
FF & chrome so IE is not an issue (thank god!)
function resetCaret(iframename){
iframe=document.getElementById(iframename).contentWindow
referenceNode = iframe.document.getElementById("caret");
if(referenceNode){
sel=iframe.getSelection()
alert(sel.focusNode)
range=sel.getRangeAt(0);
range.selectNode(referenceNode);
range.deleteContents();
}
}
Thanks for any help - this has been going on a long while now and it'd
be great to get it behind me!
Ciarán