目前我正在使用phonegap& amp; jQuery Mobile
我已经完成了完全适用于iOS和iOS的版本Android.But相同的代码不能在Windows手机上工作。当我点击任何链接,重定向到相应的页面没有加载..它仍然说“错误页面加载”。
<!DOCTYPE html>
测试
<div id="bg">
<div style="padding-top:14%;width:100%;text-align:center">
<div style="float:left;text-align:center;width:50%"><a href="list.html?qs=1"><img src="pics/btn_1.png" /></a></div>
<div style="float:left;text-align:center;width:50%"><a href="list.html?qs=2"><img src="pics/btn_2.png" /></a></div>
</div>
<div style="clear:both"></div>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
</body>
需要帮助。
答案 0 :(得分:2)
将data-ajax=false
或rel=external
添加到您的anchor
代码中。但是,如果你这样做,你将失去过渡。这告诉框架执行整页重新加载以清除URL中的Ajax哈希。如果传入设备是Windows手机(如果需要),则可以启用此功能:
$(document).on("mobileinit", function () {
//check for windows phone
$.mobile.ajaxEnabled = false;
});
否则,将您的代码转换为单个页面模板。这是一个演示:http://jsfiddle.net/hungerpain/aYW2f/
目前jQM doesn't support query string parameters。您可以使用localStorage
API将参数存储在缓存中并稍后检索它们。假设你想从这里前往index.html
:
<a href="list.html?qs=2" rel="external"><img src="pics/btn_2.png" /></a>
您需要为其添加点击事件:
$(document).on("click", "a", function() {
//gets qs=2 and changes it into ["qs",2]
var query = this.href.split["?"][2].split["="];
//construct an array out of that
var paramString = { query[0]: query[1]} ;
//store it in localstorage
locaStorage["query"] = JSON.stringify(paramString);
//continue redirection
return true;
});
在index.html
:
$(document).on("pageinit", "[data-role=page]", function() {
//store it in localstorage
var params = JSON.parse(locaStorage["query"]);
//now params will contain { "qs" : 2 }
//you could access "2" by params["qs"]
});
答案 1 :(得分:1)
我也有同样的问题,最后通过使用下面的代码来解决它
我的html页面是index.html,我正在写一个html中的所有代码
在
$.mobile.changePage( "#second", {});
在
var url = window.location.href;
url = url.split('#').pop().split('?').pop();
url = url.replace(url.substring(url.lastIndexOf('/') + 1),"index.html#second");
$.mobile.changePage(url, { reloadPage : false, changeHash : false });
并且假设您有多个html页面,那么对于另一个页面,您可以使用
var url = window.location.href;
url = url.split('#').pop().split('?').pop();
url = url.replace(url.substring(url.lastIndexOf('/') + 1),"second.html");
$.mobile.changePage(url, { reloadPage : false, changeHash : false });
答案 2 :(得分:0)
对于使用Windows Phone 7的phonegap,Web应用程序中不支持查询字符串。
但是我们可以替换?用#或其他任何东西传递数据,
喜欢转换
Sample.html?id=12312
到
Sample.html#id=12312