zoukankan      html  css  js  c++  java
  • 插件写法之脚本运行环境,mac和window检测

    (function(root, factroy){
       
    /*
    * 在这里进行对脚本运行环境的检测判断
    * 浏览器中 有window对象
    * node.js服务器端 有Global对象
    *
    * IE11的window.navigator.userAgent.toLowerCase()
    * "mozilla/5.0 (windows nt 10.0; wow64; trident/7.0; .net4.0c; .net4.0e;
    * .net clr 2.0.50727; .net clr 3.0.30729; .net clr 3.5.30729; infopath.3;
    * rv:11.0) like gecko"
    *
    * 谷歌浏览器window.navigator.userAgent.toLowerCase()
    * "mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko)
    * chrome/71.0.3578.98 safari/537.36"
    */
    if(root === undefined){
    console.log("请注意,这是Node.js运行环境")
    }else{
    console.log("请注意,这是浏览器运行环境")
    }

    // 下在是判断mac和widow的方法
    let isSystem= function(){
    /** * 是否为mac系统 * */
    let isMac = function() {
    return /macintosh|mac os x/i.test(navigator.userAgent);
    }();
    /** * 是否为windows系统 * */
    let isWindows = function() {
    return /windows|win32/i.test(navigator.userAgent);
    }();
    console.log("是否MAC系统"+isMac," , "+"是否window系统"+isWindows)
    return '判断设备mac或window系统>>>'+'isMac: '+isMac+' ,isWindows: '+isWindows;
    }();
    console.log(isSystem)
     
     
    root.Vue = factory();
     
    })(  this === window ? window:global  ,function(){
      下面是自己的工具代码
    })
  • 相关阅读:
    使用Random类生成指定范围的随机数
    js ==和===的区别
    js中的undefined
    js的split函数
    springboot发送邮件
    1032 Sharing (25分)(数组链表)
    1031 Hello World for U (20分)
    1030 Travel Plan (30分)(dijkstra 具有多种决定因素)
    1029 Median (25分)
    1026 Table Tennis (30分)
  • 原文地址:https://www.cnblogs.com/andy-lehhaxm/p/10360163.html
Copyright © 2011-2022 走看看