禁用Google地图用户代理检查 [英] Disable Google Maps user agent check
问题描述
从版本3.29开始,Google Maps JavaScript API会检查浏览器的 navigator.userAgent
并显示兼容性警告。
我在嵌入式网络浏览器控件中显示地图。默认情况下,控件在IE 7兼容模式下运行 - 我可以用 X-UA兼容
标签覆盖它。该页面如下所示:
<!DOCTYPE html>
< html>
< head>
< meta http-equiv =X-UA-Compatiblecontent =IE = edge/>
< style>
#map {
height:400px;
宽度:100%;
}
< / style>
< / head>
< body>
< div id =map>< / div>
< script>
函数initMap(){
var map = new google.maps.Map(document.getElementById('map'),{});
}
< / script>
< script async defer
src =https://maps.googleapis.com/maps/api/js?v=3.29&key=~APIKEY~&callback= initMap>
< / script>
< / body>
< / html>
使用顶部的元标记,页面呈现在IE 11模式下,但仍然使用此用户代理:
用户代理:Mozilla / 4.0(兼容; MSIE 7.0; Windows NT 10.0; WOW64; Trident / 7.0; .NET4 .c; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; InfoPath.3)
我可以重写HTTP User-Agent发送的内容,但是我无法更改JavaScript navigator.userAgent
属性。有没有一种方法可以禁用Google的检查,而不会完全禁用警告?为解决方案
对于任何有类似问题的人,您可以隐藏所有警告在这样的页面上:
< style type =text / css>
.infomsg {display:none; }
< / style>
但我想找一个更好的解决方案。
Starting with version 3.29, the Google Maps JavaScript API checks the browser's navigator.userAgent
and shows a compatibility warning.
I'm displaying a map in an embedded web browser control. By default, the control runs in IE 7 compatibility mode -- I can override that with an X-UA-Compatible
tag. The page looks like this:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<style>
#map {
height: 400px;
width: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?v=3.29&key=~APIKEY~&callback=initMap">
</script>
</body>
</html>
With the meta tag at the top, the page renders in IE 11 mode, but it still uses this user agent:
User-Agent: Mozilla/4.0 (compatible; MSIE 7.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)
I can override what HTTP User-Agent is sent, but I can't change the JavaScript navigator.userAgent
property. Is there a way to disable Google's check without disabling warnings completely?
For anyone with a similar issue, you can hide all warnings on the page like this:
<style type="text/css">
.infomsg { display: none; }
</style>
But I'd like to find a better solution.
这篇关于禁用Google地图用户代理检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!