Hi,
I've been experimenting with this for a while but didn't get anything working well — is there any way to track mouseups and selections in iframe's designMode, preferably in a cross-browser compatible mode?
Hi,
I've been experimenting with this for a while but didn't get anything working well — is there any way to track mouseups and selections in iframe's designMode, preferably in a cross-browser compatible mode?
Here's a small snippet of code I found here, hope it helps:
function setRange(rte) {
//function to store range of current selection
var oRTE;
if (document.all) {
oRTE = frames[rte];
var selection = oRTE.document.selection;
if (selection != null) rng = selection.createRange();
} else {
oRTE = document.getElementById(rte).contentWindow;
var selection = oRTE.getSelection();
rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
}
return rng;
}
Seems like you can use the selection
attribute on the document object, and then use the createRange()
method. The if-else
is probably for cross-browser support.
Here's a great Introduction to Range from Quirksmode. A great overview for getting text selections safely cross-browser.