• modernizr.js


    1.判断浏览器是否支持 h5

            if(Modernizr.canvas){
                alert(123);
            }else{
                alert(321);
            }    

    2.判断浏览器是否支持 canvas

        function supert_canvas(){
            if(Modernizr.canvas){
                alert("是");
            }else{
                alert("否");
            }
        
        }

    或者

    function supert_canvas(id){ 
      return !! document.getElementById(id).getContext("2d");
    }

    3.判断浏览器是否支持 canvas 的fliiText()

     if(Modernizr.canvastext){
          alert(123);
     }else{
          alert(321);
    }    

    或者

    function supert_canvas1_fillText(){
       var canvas1 = document.getElementById("canvas1");
       var context = canvas1.getContext("2d");
        return typeof context.fillText == 'function';
    }

    4.判断浏览器是否支持 视频播放器

    function supert_video (id){
        return !! document.getElementById(id).canPlayType;
    }

    也可以

     if(Modernizr.video){
          alert("支持");
     }else{
          alert("不支持");
    }   

    4.判断浏览器是否支持 webM 视频 编码格式

    function support_webm_video(){
      if(!support_video()){ return false}
      var v = document.createElement("video");
      return v.canPlayType('video/webm; codecs="vp8,varbis"');  
    
    }

    或者

    function supports_webm_video(){
        if(Modernizr.video){
            // 可以播放视频了,但是播放哪一种格式呢?
            if(Modernizr.video.oog){
                // 尝试在 Ogg 容器中使用 Ogg Theora + Vorbis 
            }else if (){
                // 尝试在 MP4 容器中使用 h.264 视频 + AAC  音频
            }
        
        }
    }

    5.判断浏览器是否支持 本地存储

    function support_local_storage(){
    
        return ('localStorage' in window ) && window['localStorage'] != null;
    }   

    或者

        if(Modernizr.localstorage){
            alert("ok");
        }else{
            alert("no ok");
        }

    6.判断浏览器是否支持 web workers

    function support_web_workers(){
        return !! window.Worker;
    
    }

    或者

            if(Modernizr.webworkers){
            }else{
            }

    7.判断浏览器是否支持 web workers

    function support_offline(){
        return !! window.applicationcache;
    }

    或者

            if(Modernizr.applicationcache){
            }else{
            }

    8.判断浏览器是否支持 geolocation 

    function support_geolocation(){
        return !! window.geolocation;
    }

    或者

            if(Modernizr.geolocation){
            }else{
            }

    9.判断浏览器是否支持 输入框类型

            if(Modernizr.inputtypes.data){
            }else{
            }

    10.判断浏览器是否支持 占位文本

            if(Modernizr.input.placeholder){
            }else{
            }

    11.判断浏览器是否支持 表单自动聚焦

            if(Modernizr.input.autofocus){
            }else{
            }

    或者

    function support_input_autofocus(){
        return  'autofocus' in document.createElement('input');
    }

    11.判断浏览器是否支持 微数据

    function support_input_autofocus(){
        return !! window.getItems;
     }
  • 相关阅读:
    bzoj3622: 已经没有什么好害怕的了
    BSGS
    LOJ#2320 生成树计数
    ??? cliquers
    生成函数
    洛谷P5206 数树
    01分数规划
    差分约束系统
    51nod1238 最小公倍数之和 V3
    51nod1237 最大公约数之和 V3
  • 原文地址:https://www.cnblogs.com/mjorcen/p/4447064.html
Copyright © 2020-2023  润新知