<script>
var is_gecko = /gecko/i.test(navigator.userAgent);
var is_ie = /MSIE/.test(navigator.userAgent);
function insertNodeAtSelStart()
{
if(is_gecko)
{
var S = window.getSelection();
if(!S.isCollapsed)
{
var R = S.getRangeAt(0);
var R1 = R.cloneRange();
var NN = document.createElement("startMarker");
R1.insertNode(NN);
NN.parentNode.removeChild(NN);
}
}
if(is_ie)
{
// IE-specific code
}
}
</script>
<div>
<span>one two three</span>
</div>
<input type="button" value="Insert node at selection start" onclick="insertNodeAtSelStart();" />
The first time I click the button after loading the page and selecting some text, Firefox clears the selection. Subsequently, it does not. Is this a bug in my code or in Firefox?