admin管理员组文章数量:1024944
Hi I'm trying to run a javascript function (an alert to test) but it is not firing when in a page other than the index.html.
here is an example of a page that is not firing the javascript alert ( note that < is removed from all of the tags so as to render in stack overflow):
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<script type="text/javascript" charset="utf-8" src="phonegap-1.0.0.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
//
function onDeviceReady() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
alert("test");
navigator.notification.alert("PhoneGap is working");
}
</script>
<link rel="stylesheet" href=".0rc1/jquery.mobile-1.0rc1.min.css" />
<link rel="stylesheet" href="docs/_assets/css/jqm-docs.css" />
<script src=".6.4.min.js"></script>
<script src="experiments/themeswitcher/jquery.mobile.themeswitcher.js"></script>
<script src="docs/_assets/js/jqm-docs.js"></script>
<script src=".0rc1/jquery.mobile-1.0rc1.min.js"></script>
<link rel="stylesheet" href="n_style.css" />
</head>
<body onload="onBodyLoad()">
</body>
</html>
Hi I'm trying to run a javascript function (an alert to test) but it is not firing when in a page other than the index.html.
here is an example of a page that is not firing the javascript alert ( note that < is removed from all of the tags so as to render in stack overflow):
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<script type="text/javascript" charset="utf-8" src="phonegap-1.0.0.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
//
function onDeviceReady() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
alert("test");
navigator.notification.alert("PhoneGap is working");
}
</script>
<link rel="stylesheet" href="http://code.jquery./mobile/1.0rc1/jquery.mobile-1.0rc1.min.css" />
<link rel="stylesheet" href="docs/_assets/css/jqm-docs.css" />
<script src="http://code.jquery./jquery-1.6.4.min.js"></script>
<script src="experiments/themeswitcher/jquery.mobile.themeswitcher.js"></script>
<script src="docs/_assets/js/jqm-docs.js"></script>
<script src="http://code.jquery./mobile/1.0rc1/jquery.mobile-1.0rc1.min.js"></script>
<link rel="stylesheet" href="n_style.css" />
</head>
<body onload="onBodyLoad()">
</body>
</html>
Share
Improve this question
edited Nov 2, 2011 at 18:12
Bakudan
19.5k9 gold badges55 silver badges75 bronze badges
asked Nov 2, 2011 at 17:50
AtmaAtma
29.8k57 gold badges206 silver badges306 bronze badges
1
- < is removed from all of the tags so as to render in stack overflow – Atma Commented Nov 2, 2011 at 17:59
2 Answers
Reset to default 5onDeviceReady only fires once when the app starts up. See documentation: http://docs.phonegap./en/1.0.0/phonegap_events_events.md.html#deviceready
It's the function that indicates PhoneGap is fully loaded.
Your Javascript isn't running because you don't have an onBodyLoad
function. I would wrap document.addEventListener("deviceready", onDeviceReady, false);
in an onBodyLoad
function. Also, if you are having javascript errors, try opening the page in firefox and using firebug to check for errors.
Hi I'm trying to run a javascript function (an alert to test) but it is not firing when in a page other than the index.html.
here is an example of a page that is not firing the javascript alert ( note that < is removed from all of the tags so as to render in stack overflow):
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<script type="text/javascript" charset="utf-8" src="phonegap-1.0.0.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
//
function onDeviceReady() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
alert("test");
navigator.notification.alert("PhoneGap is working");
}
</script>
<link rel="stylesheet" href=".0rc1/jquery.mobile-1.0rc1.min.css" />
<link rel="stylesheet" href="docs/_assets/css/jqm-docs.css" />
<script src=".6.4.min.js"></script>
<script src="experiments/themeswitcher/jquery.mobile.themeswitcher.js"></script>
<script src="docs/_assets/js/jqm-docs.js"></script>
<script src=".0rc1/jquery.mobile-1.0rc1.min.js"></script>
<link rel="stylesheet" href="n_style.css" />
</head>
<body onload="onBodyLoad()">
</body>
</html>
Hi I'm trying to run a javascript function (an alert to test) but it is not firing when in a page other than the index.html.
here is an example of a page that is not firing the javascript alert ( note that < is removed from all of the tags so as to render in stack overflow):
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<script type="text/javascript" charset="utf-8" src="phonegap-1.0.0.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
//
function onDeviceReady() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
alert("test");
navigator.notification.alert("PhoneGap is working");
}
</script>
<link rel="stylesheet" href="http://code.jquery./mobile/1.0rc1/jquery.mobile-1.0rc1.min.css" />
<link rel="stylesheet" href="docs/_assets/css/jqm-docs.css" />
<script src="http://code.jquery./jquery-1.6.4.min.js"></script>
<script src="experiments/themeswitcher/jquery.mobile.themeswitcher.js"></script>
<script src="docs/_assets/js/jqm-docs.js"></script>
<script src="http://code.jquery./mobile/1.0rc1/jquery.mobile-1.0rc1.min.js"></script>
<link rel="stylesheet" href="n_style.css" />
</head>
<body onload="onBodyLoad()">
</body>
</html>
Share
Improve this question
edited Nov 2, 2011 at 18:12
Bakudan
19.5k9 gold badges55 silver badges75 bronze badges
asked Nov 2, 2011 at 17:50
AtmaAtma
29.8k57 gold badges206 silver badges306 bronze badges
1
- < is removed from all of the tags so as to render in stack overflow – Atma Commented Nov 2, 2011 at 17:59
2 Answers
Reset to default 5onDeviceReady only fires once when the app starts up. See documentation: http://docs.phonegap./en/1.0.0/phonegap_events_events.md.html#deviceready
It's the function that indicates PhoneGap is fully loaded.
Your Javascript isn't running because you don't have an onBodyLoad
function. I would wrap document.addEventListener("deviceready", onDeviceReady, false);
in an onBodyLoad
function. Also, if you are having javascript errors, try opening the page in firefox and using firebug to check for errors.
本文标签: jquery mobilePhoneGap Javascript not working other than in index fileStack Overflow
版权声明:本文标题:jquery mobile - PhoneGap Javascript not working other than in index file - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745499557a2153324.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论