问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/45620026/disable-google-maps-user-agent-check