I came across this code to highlight in JavaScript. When I desected and ran on my own machine, and not jsFiddle I got the following error.
Uncaught RangeError: Maximum call stack size exceeded
http://jsfiddle.net/jme11/bZb7V/
To get around this, I looked at the other questions on StackOverflow and added in a setTimeout() function, but I still get the error. How come?
function getSelection()
{
var seltxt = '';
if (window.getSelection)
{
seltxt = setTimeout(window.getSelection(), 5000);
}
else if (document.getSelection)
{
seltxt = setTimeout(document.getSelection(), 5000);
}
else if (document.selection)
{
seltxt = setTimeout(document.selection.createRange().text, 5000);
}
else return;
return seltxt;
}