Reputation: 231
I have code such as:
var selObj = (window.getSelection && window.getSelection());
if ( selObj !== null && selObj.anchorOffset) {
var off = selObj.anchorOffset;
As far as I know anchorOffset should be a long - it is indeed a long in firefox and IE. But in Webkit, if I have a large selection over 65K, it truncates - i.e. I'm getting an int.
Is this a bug? Is there something else that I can use instead as a workaround?
Thanks.
I'm adding a very simple page that shows the problem:
<body>
<label ondblclick="var selObj = (window.getSelection && window.getSelection()); alert(selObj.anchorOffset);">
really really long text here
...
...
..
at 65K it wrpas around..
</label>
</body>
If you replace the .... with a lot of text (over 65K characters) and open the page in chrome or safari and double click past the 65K mark you'll see it counts it as if it overflows.
It's as if there are multiple selections - but I have no clue how to get how many times it "wrapped around"
Any help greatly appreciated.
Upvotes: 0
Views: 83
Reputation: 18402
JavaScript only has one number type (which is an IEEE-754 compliant floating-point double), so the difference you're seeing is probably an implementation difference in window.getSelection()
.
Possible workarounds depend on the concrete use-case.
Upvotes: 0