zoukankan      html  css  js  c++  java
  • js-奇技淫巧

    • 执行浏览器复制命令

    注:只能复制文本框内的文字( input / textarea )

    function jsCopy(){ 
        var e = document.getElementById("content");//对象是content 
        e.select(); //选择对象 
        document.execCommand("Copy"); //执行浏览器复制命令
        alert("已复制好,可贴粘。"); 
    } 
    
    // Converts canvas to an image
    function convertCanvasToImage(canvas) {
        var image = new Image();
        image.src = canvas.toDataURL("image/png");
        return image;
    }
    
    • 低级浏览器升级提示
    <!--IE7以下极低级浏览器升级提示-->
    <!--[if lte IE 7]>
      <script>window.location.href='http://cdn.dmeng.net/upgrade-your-browser.html?referrer='+location.href;</script>
    <![endif]-->
    • 判断浏览器类型
    // 判断浏览器类型
    function getBrowser() {
        let ua = window.navigator.userAgent;
        let isIE = window.ActiveXObject != undefined && ua.indexOf("MSIE") != -1;
        let isEdge = ua.indexOf("Trident") != -1;
        let isFirefox = ua.indexOf("Firefox") != -1;
        let isOpera = window.opr != undefined;
        let isChrome = ua.indexOf("Chrome") && window.chrome;
        let isSafari = ua.indexOf("Safari") != -1 && ua.indexOf("Version") != -1;
        if (isIE) {
          return "IE";
        } else if (isFirefox) {
          return "Firefox";
        } else if (isOpera) {
          return "Opera";
        } else if (isChrome) {
          return "Chrome";
        } else if (isSafari) {
          return "Safari";
        } else if (isEdge) {
          return "isEdge";
        } else {
          return "Unkown";
        }
    }
    
    //判断是移动端还是PC
    function isMobileOrPC(){
        if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
            return 'mobile';
        }
        return 'pc';
    }
      
    export default {
        methods : {
            getBrowser,
            isMobileOrPC
        }
    }
    
    • 禁止、恢复H5页面滑动
    //禁止H5页面滑动
    document.body.style.overflow = 'hidden';
    function _preventDefault(e) {
        e.preventDefault();
    }
    window.addEventListener('touchmove', _preventDefault);
    
    //恢复滑动
    document.body.style.overflow = 'auto';
    window.removeEventListener('touchmove', _preventDefault);
    

      

  • 相关阅读:
    通用js模块02:validutils.js
    通用js模块04:cookieUtils.js
    通用js模块03:formatutils.js
    通用js模块01:stringutils.js
    应用开发平台与代码生成工具感想
    linq to sql 中isnumeric的使用
    很惭愧啊
    错误:”未能加载文件或程序集“System.Web.Mvc, Version=2.0.0.0” 解决方法
    今天又温习了一下磁盘阵列的概念
    ashx的说明
  • 原文地址:https://www.cnblogs.com/zhenjianyu/p/13405056.html
Copyright © 2011-2022 走看看