关于firefox获取选中页面文字的对象
2007-10-15 10:33
399 查看
<script language="javascript">
var agt=navigator.userAgent.toLowerCase();
var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("omniweb") == -1));
function a(){
var myArea = document.getElementById("s");
var selection;
if (!ie){
if (myArea.selectionStart!= undefined) {
selection = myArea.value.substr(myArea.selectionStart, myArea.selectionEnd - myArea.selectionStart);
}
}else{
if (window.getSelection){
selection = window.getSelection();
}else if (document.getSelection){
selection = document.getSelection();
}else if (document.selection){
selection = document.selection.createRange().text;
}
}
alert(selection)
}
</script>
<input type="text" value="testtest" id="s" name="s"
onmouseup="javascript:a()" />
最近在用js做个网页划词搜索的小项目,获取页面选中文字IE下用
document.selection.createRange().text;
firefox
为
window.getSelection();
var agt=navigator.userAgent.toLowerCase();
var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("omniweb") == -1));
function a(){
var myArea = document.getElementById("s");
var selection;
if (!ie){
if (myArea.selectionStart!= undefined) {
selection = myArea.value.substr(myArea.selectionStart, myArea.selectionEnd - myArea.selectionStart);
}
}else{
if (window.getSelection){
selection = window.getSelection();
}else if (document.getSelection){
selection = document.getSelection();
}else if (document.selection){
selection = document.selection.createRange().text;
}
}
alert(selection)
}
</script>
<input type="text" value="testtest" id="s" name="s"
onmouseup="javascript:a()" />
最近在用js做个网页划词搜索的小项目,获取页面选中文字IE下用
document.selection.createRange().text;
firefox
为
window.getSelection();
相关文章推荐
- Javascript 获取页面上选中的文字
- JS - 获取页面上选中的文字
- 如何获取页面上鼠标选中的文字
- Javascript 获取页面上选中的文字
- 关于页面上如何获取用户选中的多个checkbox所传递的值
- js 获取页面上选中的文字
- js通过事件获取页面元素对象-适用于IE、FireFox
- JS获取页面里鼠标选中的文字
- 关于layui(layer)子页面获取不到父页面jQuery对象的问题。
- JQuery获取页面上选中的checkbox
- google chome 加载页面根据name 获取对象
- 关于火狐(firefox)及ie下event获取的两种方法
- 关于在IE9下RequiredFieldValidator出现“无法获取属性“toLowerCase”的值: 对象为 null 或未定义”的Bug
- Rcp(插件开发) 如何获取当前视图选中的对象
- 获取树对象中选中的节点
- Delphi richedit获取选中文字
- 页面间(窗口间)的取值赋值及获取iframe下的window对象
- JS获取事件对象,获取事件的源对象(Firefox,IE)
- Delphi richedit获取选中文字
- js获取鼠标选中的文字