Hi,
There are many tables in my HTML page. When a user hovers on a table, it should be automatically selected(onmouseover event) so that the user can copy(Ctrl+v) it to clipboard. I searched for a way in stackoverflow and ended up with the following code. But it only works in Firefox (window.getSelection() doesn't work in IE). How can I make it work in IE?
var prevRange = null;
function s(node) {
var s = window.getSelection();
var r = document.createRange();
r.selectNode(node);
if (prevRange) {
s.removeRange(prevRange);
}
s.addRange(r)
prevRange = r;
}
For some unknown reason, I can't use s.removeAllRanges() in FF. It gives "invalid label" error. hmmm.
Also, is there a way to programmatically copy the selected code to clipboard?
Thanks.
Sam