×

addNavBackListener()

Description

The addNavBackListener method registers a listener for activation of the hardware back-button on phones based on the Nokia Asha software platform 1.0. The method enables developers to add support for standard platform back stepping to web apps.

If a back event listener isn't defined in a web app running on the Nokia Asha software platform 1.0 and the user presses the back key, the platform will prompt the user by asking if they want to exit the web app. On earlier phones, based on the Series 40 platform, the listener registered by addNavBackListener never fires.

The back event listener supports calling MWL and JavaScript functions.

This is a synchronous method.

Syntax

<static> mwl.addNavBackListener(targetNode, listener)

Parameters

The following table describes the parameters used in an addNavBackListener call.

Table 1. timer parameters
Parameter Type Description
targetNode String This string identifies the listener.
listener String This is a list of semicolon-separated JavaScript statements to execute when the listener fires. This can be any combination of MWL and non-MWL statements. With non-MWL code, remember that it runs on the proxy server rather than the phone, which causes a client-server communications lag.

Return value

The addNavBackListener method does not return a value.

Example code

In this example a listener is added to page 2 of the web app, when the listener fires the MWL Show() and Hide() methods are used to show the first page of the web app and hide the other three pages.

mwl.addNavBackListener('#page2', "mwl.show('#page1');mwl.hide('#page2');mwl.hide('#page3');mwl.hide('#page4');");

It's also possible to mix MWL calls with JavaScript function calls. In this example returning back from page 3 shows page 2 and calls the JavaScript function populatePage2() to build the content for page 2.

mwl.addNavBackListener('#page3', "mwl.hide('#page1');mwl.show('#page2'); populatePage2();
   mwl.hide('#page3');mwl.hide('#page4')");

function populatePage2(){
   document.getElementById('page2img').innerHTML = "<img  src=\"s40-theme/images/asha310.png\" alt=\"310\" />";
}

In addition, you can find an example web app that implements addNavBackListener in the web apps samples, the example is called BackKeySample.


Last updated 31 May 2013

Back to top

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×