黑莓网络作品怎么每次应用启动触发事件 [英] Blackberry Web Works how to fire event everytime the app is launched

查看:164
本文介绍了黑莓网络作品怎么每次应用启动触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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>

我在使用类似上述的WebWorks黑莓手机内置的应用程序。我需要上述的helloWorld()函数被解雇每次用户打开应用程序。

I have an app built using Blackberry WebWorks similar to above. I need the above helloWorld() function to be fired everytime the user open the app.

问题是的onload功能,只有当应用程序首次推出解雇,或者当用户退出通过点击应用程序在移动挂断键上的移动后退按钮不点击的时候。

The problem is "onload" function only fired when the app first launched, or when the user exit the app by clicking the "hang up button on the mobile", not when clicking on "back button on the mobile".

任何建议?

推荐答案

我觉得你有兴趣启动应用程序启动,不仅每次的功能,而且当应用从后台检索(这意味着,当您的应用程序没有关闭,但它在后台运行,虽然你不与它交互)。

I think that you are interested in launching the function not only every time the app is started, but also when the app is retrieved from the background (this means when your app is not closed, but it is running in the background although you are not interacting with it).

我建议你用科尔多瓦(前PhoneGap的),并采取一看的恢复事件。使用给那里的例子,我想你需要的东西是这样的:

I suggest you use Cordova (former Phonegap) and take a look at the "resume" event. Using the example given there, I think you would need something like this:

<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>

您可以下载您需要这里的文件。我还没有测试code。试试吧,让我知道它是否适合你。

You may download the files you need here. I haven't test the code. Try it and let me know if it works for you.

这篇关于黑莓网络作品怎么每次应用启动触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆