我想指定firefox选择一个范围。我可以轻松地使用IE,使用range.select();.看来,FFX预计一个DOM元素。我错了吗,还是有更好的方法去解决这个问题?范围选择和Mozilla
我首先获取文本选择,将其转换为范围(我认为?)并保存文本选择。这是我从最初得到的范围:
// Before modifying selection, save it
var userSelection,selectedText = '';
if(window.getSelection){
userSelection=window.getSelection();
}
else if(document.selection){
userSelection=document.selection.createRange();
}
selectedText=userSelection;
if(userSelection.text){
selectedText=userSelection.text;
}
if(/msie|MSIE/.test(navigator.userAgent) == false){
selectedText=selectedText.toString();
}
origRange = userSelection;
我稍后更改选择(成功)。我通过在IE中的范围以及在ffx中的dom ID来实现。但是在我这样做后,我想将选项设置回原来的选择。
这就像在IE浏览器的魅力:
setTimeout(function(){
origRange.select();
},1000);
我愿做这样的事情在FFX:
var s = w.getSelection();
setTimeout(function(){
s.removeAllRanges();
s.addRange(origRange);
},1000);
不幸的是,FFX一直没有合作的,这不工作。有任何想法吗?
你能告诉我们一些代码?这会让我们更容易看到发生了什么。我想你读了https://developer.mozilla.org/en/DOM/Selection – 2010-04-19 23:31:44