gpt4 book ai didi

jquery - Webshims、IE8 和地理定位

转载 作者:行者123 更新时间:2023-11-28 05:05:33 26 4
gpt4 key购买 nike

我想要多个选项来让我们的 IE8 笔记本电脑使用地理定位,并且研究了 Google Chrome Frame(有效)和 jquery polyfill(这是我正在努力工作的)。该示例来自的网站是 webshims并且我已验证上述演示页面在 IE8 中有效,但我无法为自己重新创建该示例。这是我的 jsp:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Geolocation</title>
<script src="<c:url value="/js/jquery-1.6.4.min.js"/>" type="text/javascript"></script>
<script src="<c:url value="/js/modernizr-latest.js"/>" type="text/javascript"></script>
<script src="<c:url value="/js/polyfiller.js"/>" type="text/javascript"></script>
<script type="text/javascript">
//http://afarkas.github.com/webshim/demos/demos/geolocation.html
$.webshims.polyfill();
navigator.geolocation.getCurrentPosition(function(pos){ $("#status").html("found you! latitude: "+ pos.coords.latitude +"/longitude: " + pos.coords.longitude); });
</script>
</head>
<body>
<p>Finding your location: <span id="status">checking...</span></p>
</body>
</html>

它适用于任何原生支持地理定位的浏览器,但 polyfill 似乎无法在 IE8 上发挥作用。我收到以下错误:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; chromeframe/15.0.874.121; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) Timestamp: Wed, 7 Dec 2011 17:48:06 UTC

Message: 'navigator.geolocation' is null or not an object Line: 13 Char: 7 Code: 0 URI: ../GeoLocation/jquery.action

我是否遗漏了使此功能正常运行的某些内容?

最佳答案

您需要先激活 polyfill。请参阅头部包含以下脚本的示例源代码:

$.webshims.setOptions('geolocation', {
confirmText: '{location} wants to know your position. It is Ok to press Ok.'
});
//load all polyfill features
//or load only a specific feature with $.webshims.polyfill('feature-name');
$.webshims.polyfill();

更新:这个 HTML 页面在 IE9、IE7 和 Chrome 中都工作得很好

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Geolocation</title>
<script src="http://code.jquery.com/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="http://afarkas.github.com/webshim/demos/js-webshim/minified/extras/modernizr-custom.js" type="text/javascript"></script>
<script src="http://afarkas.github.com/webshim/demos/js-webshim/minified/polyfiller.js" type="text/javascript"></script>
<script type="text/javascript">
//http://afarkas.github.com/webshim/demos/demos/geolocation.html
$.webshims.setOptions('geolocation', {
confirmText: '{location} wants to know your position. It is Ok to press Ok.'
});
$.webshims.polyfill();
$(function(){
navigator.geolocation.getCurrentPosition(function(pos){ $("#status").html("found you! latitude: "+ pos.coords.latitude +"/longitude: " + pos.coords.longitude); });
});
</script>
</head>
<body>
<p>Finding your location: <span id="status">checking...</span></p>
</body>
</html>

确保使用 HTTPL//而不是 FILE://

关于jquery - Webshims、IE8 和地理定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8420259/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com