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

      

  • 相关阅读:
    hdu2328 Corporate Identity
    hdu1238 Substrings
    hdu4300 Clairewd’s message
    hdu3336 Count the string
    hdu2597 Simpsons’ Hidden Talents
    poj3080 Blue Jeans
    poj2752 Seek the Name, Seek the Fame
    poj2406 Power Strings
    hust1010 The Minimum Length
    hdu1358 Period
  • 原文地址:https://www.cnblogs.com/zhenjianyu/p/13405056.html
Copyright © 2011-2022 走看看