zoukankan      html  css  js  c++  java
  • 网页获取页面上选择的内容

    function getSelectedContents(){
    if (window.getSelection) { //chrome,firefox,opera
      var range=window.getSelection().getRangeAt(0);
      var container = document.createElement('div');
      container.appendChild(range.cloneContents());
      return container.innerHTML;
      //return window.getSelection(); //只复制文本
    }
    else if (document.getSelection) { //其他
      var range=window.getSelection().getRangeAt(0);
      var container = document.createElement('div');
      container.appendChild(range.cloneContents());
      return container.innerHTML;
      //return document.getSelection(); //只复制文本
    }
    else if (document.selection) { //IE特有的
      return document.selection.createRange().htmlText;
      //return document.selection.createRange().text; //只复制文本
    }
    }

  • 相关阅读:
    Less-21
    Less-22
    Less-21
    Less-20
    ssrf redis gopher
    Less19
    Less18
    Arm 系统查看、修改系统时间
    通过 grpc 请求标头发送自定义数据
    gRpc 空参数
  • 原文地址:https://www.cnblogs.com/wcp-spring/p/3388743.html
Copyright © 2011-2022 走看看