zoukankan      html  css  js  c++  java
  • 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;
     }
  • 相关阅读:
    从gcc代码看go语言goroutine和channel实现
    /proc/$pid/maps文件中各个空间段的意义
    gdb通过frame切换栈帧之后寄存器是否准确
    ssh channel功能实现源码分析
    protobuf中extension的使用
    从反射看protobuf的部分实现
    最新JetBrains PyCharm 使用教程--常用功能设置(三)
    IntelliJ IDEA 中设置左菜单字体, 编辑器字体和控制台的字体
    最新JetBrains PyCharm 使用教程--安装教程(一)
    开源管理系统
  • 原文地址:https://www.cnblogs.com/mjorcen/p/4447064.html
Copyright © 2011-2022 走看看