点击按钮在其他页面加载谷歌地图(jquery mobile/javascript)
Click Button to load Google Maps on other page (jquery mobile/javascript)
所以我正在尝试制作一个带有湖页面的移动应用程序。我希望能够点击一个按钮链接,并被带到一个有地图的页面。这一切都是在Jquery mobile中完成的,我不想要外部页面。(就像"#地图页")
我已经完成了我想要的代码。但就让它在点击事件中启动而言,我运气不佳。我已经经历了很多这样的例子。我想在页面上加载地图,这样移动应用程序就不需要加载太多地图了。
我在jsFiddle上做了一个例子。
http://jsfiddle.net/Ajfvr/
因此,我不需要使用onload属性加载,而是需要在单击页面链接后将其加载到另一个嵌套页面(全屏)上。因此,js在点击链接之前不会启动。
请帮助<3谢谢。
代码:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<script type="text/javascript" src="../jquery/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3&sensor=false&language=en"></script>
<script type="text/javascript" src="../cordova-2.3.0.js"></script>
<style>
html, body, #map_canvas {
margin: 0;
padding: 0;
height: 100%;
}
</style>
<script type="text/javascript">
function detectBrowser() {
var useragent = navigator.userAgent;
var mapdivMap = document.getElementById("map_canvas");
if (useragent.indexOf('iPhone') != -1 || useragent.indexOf('Android') != -1 ) {
mapdivMap.style.width = '100%';
mapdivMap.style.height = '100%';
initialize();
} else {
mapdivMap.style.width = '600px';
mapdivMap.style.height = '800px';
initialize();
}
};
function initialize() {
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(43.464258,-80.52041),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);
var marker = new google.maps.Marker({
position: map.getCenter(),
map: map,
title: 'Waterloo'
});
}
google.maps.event.addDomListener(window, 'load', detectBrowser);
</script>
</head>
<body onload="detectBrowser()">
<div id="map_canvas"></div>
</body>
</html>
我从你的问题中了解到,你想在一个全新的页面中加载地图。或者,如果你想在同一页上加载地图,但又延迟加载地图,你可以简单地点击按钮调用函数,并使用Javascript在覆盖DIV中加载地图。
jQuery Mobile有一种预取(提前加载)页面的方法。如果你想提前加载地图,你也可以研究一下。
相关文章:
- 无法从jquery Mobile导航栏重定向到另一个页面
- jquery mobile上多个页面上的一个表单
- window.location使用jquery mobile实现chrome跳转
- 防止jQuery Mobile中的ajax缓存
- 如何在JQUERY Mobile上放置谷歌地图
- JQuery Mobile Javascript复杂方程式
- jQuery Mobile Undefined不是一个函数
- jQuery mobile not going through ID
- 如何使用javascript或jquery mobile从url读取和显示XML文件
- jQuery Mobile Collapse上的AJAX请求
- 应用程序在呈现Jquery Mobile之前显示无样式的Html
- 如何在jQuery Mobile 1.4 Datepicker中创建事件
- UIWebview赢得't通过基本身份验证加载动态加载的资源(通过jQuery mobile)
- jQuery Mobile到其他页面的锚链接不起作用
- 如何在jQuery Mobile中设置100%宽度的输入类型日期
- JQuery Mobile破坏了我的布局:如何禁用自动打字
- 防止用户在jQuery Mobile中ajax加载页面时单击其他位置
- 根据手机上是否存在文件,在jQuery mobile中动态填充列表视图
- Image Sprites和jQuery Mobile Ajax导航的问题
- jQuery Mobile:如何在$.Mobile.changePage之前运行回调函数