zoukankan      html  css  js  c++  java
  • 关于firefox获取选中页面文字的对象

    <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();

  • 相关阅读:
    Struts2
    HIbernate缓存
    spring的静态代理和动态代理
    JVM与垃圾回收机制(GC)和类的生命周期
    java开发设计六大基本原则
    数据表链表结构
    HashMap的底层实现
    string与位运算
    log4j和logback
    C#深入类的方法
  • 原文地址:https://www.cnblogs.com/wangxiang/p/924438.html
Copyright © 2011-2022 走看看