2017-08-10 34 views
1

從版本3.29開始,Google Maps JavaScript API會檢查瀏覽器的navigator.userAgent並顯示兼容性警告。禁用Google地圖用戶代理檢查

我在嵌入式Web瀏覽器控件中顯示地圖。默認情況下,控件在IE 7兼容模式下運行 - 我可以用X-UA-Compatible標籤覆蓋該控件。該網頁看起來是這樣的:

<!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> 

在頂部的meta標籤,頁面呈現在IE 11的模式,但它仍然使用這個用戶代理:

的User-Agent:Mozilla的/ 4.0 (兼容; 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 )

我可以覆蓋HTTP User-Agent發送的內容,但我無法更改JavaScript navigator.userAgent屬性。有沒有辦法禁用Google的支票而不完全禁用警告?

回答

1

對於有類似問題的人,你可以隱藏這樣的網頁上的所有警告:

<style type="text/css"> 
    .infomsg { display: none; } 
</style> 

但我想找到一個更好的解決方案。