【问题标题】:How does java script know what features a specific browser support?javascript 如何知道特定浏览器支持哪些功能?
【发布时间】:2017-02-03 12:42:02
【问题描述】:

当我们想要使用一个特性时,我们通常需要检查浏览器是否支持,例如 navigator.GeoLocation 对象。

但它们究竟在哪里以及如何存在?浏览器运行时是物理dll文件还是完全保存在内存中? 谢谢

【问题讨论】:

    标签: html google-chrome browser


    【解决方案1】:

    您可以使用以下软件包

    这里:https://modernizr.com/docs/#what-is-feature-detection

    但是想在 GeoLocation 中使用这种类型的代码

    // Try HTML5 geolocation
        if(navigator.geolocation) {
          navigator.geolocation.getCurrentPosition(function(position) {
            var pos = new google.maps.LatLng(position.coords.latitude,
                                             position.coords.longitude);
    
            var infowindow = new google.maps.InfoWindow({
              map: map,
              position: pos,
              content: 'Location found using HTML5.'
            });
    
            map.setCenter(pos);
          }, function() {
            handleNoGeolocation(true);
          });
        } else {
          // Browser doesn't support Geolocation
          handleNoGeolocation(false);
        }
    

    【讨论】:

      猜你喜欢
      • 2023-03-30
      • 2016-08-31
      • 2017-05-04
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多