2012-05-11 65 views
2
<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> 

我有一個使用Blackberry WebWorks構建的應用程序,與上面類似。我需要上面的helloWorld()函數在用戶每次打開應用程序時觸發。Blackberry Web Works如何在每次啓動應用程序時觸發事件

問題是隻有當應用程序第一次啓動時,或者當用戶通過點擊「掛機按鈕在手機上」退出應用程序,而不是在點擊「手機上的後退按鈕」時纔會觸發「加載」功能。

有什麼建議嗎?

回答

1

我認爲你是有意推出不僅每次應用程序啓動時的功能,而且當應用從後臺檢索(這意味着,當你的應用程序沒有關閉,但它在後臺運行雖然你沒有與它互動)。

我建議你使用科爾多瓦(前Phonegap),並看看"resume" event。使用給那裏的例子,我想你會需要像這樣:

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

你可以下載你需要here的文件。我沒有測試代碼。試試吧,讓我知道它是否適合你。

+0

感謝回答,但我已經決定放棄WebWorks的,現在做本地Eclipse和Java - 一切都得到真正的順利,到目前爲止,所有我需要有壓倒一切「激活()」函數。不能嘗試的解決方案,但給予好評。謝謝。 – friend

+0

融入本土,可能是最好的選擇。祝你好運與您的應用程序)。 – Arturo

相關問題