Phonegap构建 - Javascript无法正常工作
问题描述:
我正在开发PhoneGap构建中的测试应用程序。目前,我正在尝试在应用加载时重定向到一个页面。但是当我尝试这样做时,它不会重定向,而只能保留在index.html页面中。我正在使用TestObject来测试应用程序。Phonegap构建 - Javascript无法正常工作
的index.html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" charset="utf-8">
function init() {
document.addEventListener("deviceready", onDeviceReady, true);
}
function onDeviceReady() {
alert("Device is ready");
}
</script>
</head>
<body onload="init();">
<input type="button" onclick="location.href='http://google.com';" value="Go to Google" />
Hai welcome to my app
</body>
</html>
config.xml中
<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "com.mydomain.mobileApp"
versionCode = "1"
version = "1.0.0" >
<!-- versionCode is Android only -->
<!-- version is in major.minor.patch format -->
<name>My App</name>
<description>
An example for phonegap build app which wont show up in the playstore.
</description>
<author href="https://YourWebsite.com" email="[email protected]">
Name Of The Author
</author>
</widget>
当我测试这个浏览器,在单击按钮,它会重定向到http://google.com。但是当我上传apk(从phonebuild构建)并上传到TestObject时,按钮即将到来。但点击它没有任何反应。当我测试应用程序时,我越来越喜欢这个。
谁能帮我找到这个问题。提前致谢。
答
在HTML文件的head
部分包括phonegap.js
,不要使Click事件处理程序内联。在script
部分注册事件处理程序。并确保您已包含whitelist
插件。试试下面的代码:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="phonegap.js"></script>
<script type="text/javascript">
function myFun(){
document.getElementById("myBtn").addEventListener("click", function(){
location.href='http://google.com';
});
}
</script>
</head>
<body onload="myFun()">
<button id="myBtn">Go to Google</button>
Hai welcome to my app
</body>
</html>
答
您需要包括科尔多瓦在您的应用程序
,并尝试这种之一,也是
document.addEventListener("deviceready", function(){
alert("Device ready Fire");
},true);
+0
@ RAj ..我得到了警报..但仍然没有重定向到谷歌页面。 – Jenz
http://phonegap.com/getstarted/请按照教程和尝试指定你的问题。 –
你在使用phonegap-cli还是phonegap-app-desktop? –
@ HassanALi ..我使用phonegap build .. – Jenz