Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
Posts: 125
Registered: ‎03-06-2012
My Device: Z10
My Carrier: 3 Italia

Back button in BB OS 5

Hi, I am doing a webworks app for BB OS 5.

 

I want the back button to go to a specific page, not the previous page.

 

So I added 

<feature id="blackberry.system.event" version="1.0.0"/>

in config.xml

 

and this javascript

blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK,

function() {

   window.location.href = 'mypage.htm';

   return false;

});

 

the problem is that it does not go to mypage.htm when i press back, it just go backwards in history.

What I did wrong?

If i remove the feature on config.xml, it exits when i press back button


Contributor
Posts: 32
Registered: ‎10-03-2011
My Device: 9900
My Carrier: developer

Re: Back button in BB OS 5

hi,

 

try this

 

 

<html>
<head>
<script type="text/javascript">
function backfun()
{
    window.location = "/index.html";
    window.close();
}

</script>
</head>
<body>
<input type="button" value = "BACK" onclick="backfun()">
</body>
</html>

Developer
Posts: 125
Registered: ‎03-06-2012
My Device: Z10
My Carrier: 3 Italia

Re: Back button in BB OS 5

I meant the hardware back button

This code just adds a software button, right?

 

If I don't intercept the hardware back button, the app will close, this is counter-intuitive

Contributor
Posts: 32
Registered: ‎10-03-2011
My Device: 9900
My Carrier: developer

Re: Back button in BB OS 5

[ Edited ]

hi,

 try this

 

 blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK,
            function()
            {
               window.location = '/Login.html';
               window.close();
            });

Developer
Posts: 125
Registered: ‎03-06-2012
My Device: Z10
My Carrier: 3 Italia

Re: Back button in BB OS 5

[ Edited ]

Nope, it does not work 

 

tried also this, still go back in history instead of closing:

 

blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK,
            function()
            {
               window.close();
            });

edit: works perfectly on BB OS 6, doesn't on OS 5 Smiley Frustrated 

Developer
Posts: 125
Registered: ‎03-06-2012
My Device: Z10
My Carrier: 3 Italia

Re: Back button in BB OS 5

Did this, it works

 

function atload() {
//otherwise i can't debug in firefox xD
if (navigator.userAgent.indexOf("Firefox")==-1)
trapForBackKey();
}

window.onload=atload;
 
  function trapForBackKey() {
    blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK, handleBack);
  }
 
  function handleBack() {
    alert("hello");
  }

 

Trusted Contributor
Posts: 227
Registered: ‎09-03-2010
My Device: Not Specified

Re: Back button in BB OS 5

try

 

<script type="text/javascript">

trapForBackKey();

  function trapForBackKey() {
    blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK, handleBack);
  }

  function handleBack() {
    document.location ="mypage.htm"
  }
</script>

 

Developer
Posts: 125
Registered: ‎03-06-2012
My Device: Z10
My Carrier: 3 Italia

Re: Back button in BB OS 5

[ Edited ]

Still does not work as intended (if i replace it with an alert, it appears, so it is intercepted)

I will rewrite my app with bbUI.js  (from documentation: The toolkit is designed to use the Application Event WebWorks API so that it can trap the "back" hardware key and automatically handle popping the last screen off of the stack.  )

Trusted Contributor
Posts: 103
Registered: ‎03-31-2011
My Device: Curve 9330
My Carrier: Verizon

Re: Back button in BB OS 5

blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK,
function()
{
location.href = 'Home.htm';
});

This has to be part of your body onload="***" function
Trusted Contributor
Posts: 227
Registered: ‎09-03-2010
My Device: Not Specified

Re: Back button in BB OS 5

be sure that in the config.xml is set override the back button default behavior to exit application, just add rim:backButton="exit".

example :

<widget xmlns="http://www.w3.org/ns/widgets" xmlns:rim="http://www.blackberry.com/ns/widgets" version="1.0.0.0" rim:backButton="exit">