Javascript Blackberry Web解决了每次应用程序启动时如何触发事件的问题 函数helloWorld(){ 警报(“你好世界”); } 你好,世界
我有一个应用程序使用黑莓WebWorks类似上述。我需要在用户每次打开应用程序时激发上面的helloWorld()函数 问题是“onload”功能仅在应用程序首次启动时启动,或者当用户通过单击“手机上的挂断按钮”退出应用程序时启动,而不是在单击“手机上的后退按钮”时启动Javascript Blackberry Web解决了每次应用程序启动时如何触发事件的问题 函数helloWorld(){ 警报(“你好世界”); } 你好,世界,javascript,jquery,html,blackberry,blackberry-webworks,Javascript,Jquery,Html,Blackberry,Blackberry Webworks,我有一个应用程序使用黑莓WebWorks类似上述。我需要在用户每次打开应用程序时激发上面的helloWorld()函数 问题是“onload”功能仅在应用程序首次启动时启动,或者当用户通过单击“手机上的挂断按钮”退出应用程序时启动,而不是在单击“手机上的后退按钮”时启动 有什么建议吗?我认为您不仅有兴趣在每次启动应用程序时启动该功能,而且有兴趣在从后台检索应用程序时启动该功能(这意味着您的应用程序未关闭,但它在后台运行,尽管您没有与之交互) 我建议您使用Cordova(以前的Phonegap)并
有什么建议吗?我认为您不仅有兴趣在每次启动应用程序时启动该功能,而且有兴趣在从后台检索应用程序时启动该功能(这意味着您的应用程序未关闭,但它在后台运行,尽管您没有与之交互) 我建议您使用Cordova(以前的Phonegap)并查看一下。使用这里给出的示例,我认为您需要以下内容:
<html>
<head>
<meta name="viewport" id="viewport" content="height=device-height,width=device-width,user-scalable=no"/>
<script type="text/javascript">
function helloWorld() {
alert("Hello World");
}
</script>
</head>
<body onload="helloWorld();">
<h1>Hello World</h1>
</body>
</html>
科尔多瓦简历示例
//加载Cordova后调用onDeviceReady。
//此时,文档已加载,但cordova-1.7.0.js尚未加载。
//加载Cordova并与本机设备通话时,
//它将调用事件“DeviceRady”。
函数onLoad(){
文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
}
//Cordova已加载,现在可以安全地调用Cordova方法
函数ondevicerady(){
文件。附录列表(“简历”,onResume,false);
//调用您感兴趣的函数。
helloWorld();
}
//处理恢复事件
函数onResume(){
helloWorld();
}
函数helloWorld(){
警报(“你好世界”);
}
你可以下载你需要的文件。我还没有测试代码。尝试一下,让我知道它是否适合您。谢谢您的回复,但我决定放弃WebWorks,现在使用Eclipse和Java进行本机操作-到目前为止,一切都非常顺利,我只需要重写“activate()”函数。无法尝试您的解决方案,只能向上投票。谢谢。土生土长可能是最好的选择。祝你的应用好运;)。
<html>
<head>
<title>Cordova Resume Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-1.7.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Call onDeviceReady when Cordova is loaded.
// At this point, the document has loaded but cordova-1.7.0.js has not.
// When Cordova is loaded and talking with the native device,
// it will call the event `deviceready`.
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// Cordova is loaded and it is now safe to make calls Cordova methods
function onDeviceReady() {
document.addEventListener("resume", onResume, false);
// Call the function you are interested in.
helloWorld();
}
// Handle the resume event
function onResume() {
helloWorld();
}
function helloWorld(){
alert('Hello World');
}
</script>
</head>
<body onload="onLoad()">
</body>
</html>