11-27-2012 06:09 AM - edited 11-27-2012 06:31 AM
Hello, I have seen some post about this but none of them have solved my issue. I´m not able to trap the back button event on my webworks app. My app just exits on back key pressed . The problem only happens in the real device, with the Chrome plugin its working fine the same code.
Edit: I have a BB 9300 os6, and another one with os5, doesnt work on both.
My config.xml
<?xml version="1.0" encoding="UTF-8"?> <widget xmlns="http://www.w3.org/ns/widgets" xmlns:rim="http://www.blackberry.com/ns/widgets" version="2.0" rim:header="RIM-Widget: rim/widget"> <author href="http://www.example.com/" rim:copyright="Copyright 1998-2012 My Corp">My Corp</author> <name>FIDS_V3</name> <icon src="img/icon.png"/> <content src="index.html"/> <access subdomains="true" uri="*"/> <rim:loadingScreen backgroundImage="img/imgFIDS.png" foregroundImage="img/ajax-loader.gif" onRemotePageLoad="true" onLocalPageLoad="true" onFirstLaunch="true"> </rim:loadingScreen> <rim:allowInvoke Params="true" /> <rim:connection timeout="60000"> <id>TCP_WIFI</id> <id>TCP_CELLULAR</id> <id>BIS-B</id> <id>MDS</id> <id>WAP2</id> <id>WAP</id> </rim:connection> <rim:cache disableAllCache="true"/> <feature id="blackberry.app" required="true" version="1.0.0.0"/> <feature id="blackberry.app.event" required="true" version="1.0.0.0"/> <feature id="blackberry.system" required="true" version="1.0.0.0"/> <feature id="blackberry.system.event" required="true" version="1.0.0"/> <feature id="blackberry.identity" required="true" version="1.0.0"/> <feature id="blackberry.push" required="true" version="1.0.0"/> <feature id="blackberry.utils" required="true" version="1.0.0.0"/> <feature id="blackberry.invoke" required="true" version="1.0.0.0"/> <feature id="blackberry.io.file" required="true" version="1.0.0.0"/> <feature id="blackberry.io.dir" required="true" version="1.0.0.0"/> </widget>
and the javascript code used in index.html
<script>
function trapForBackKey(){
blackberry.system.event.onHardwareKey(blackberry.s ystem.event.KEY_BACK,function(){alert('back event trapped3');});
}
</script>
Solved! Go to Solution.
11-27-2012 11:57 AM
Where/what is calling your trapForBackKey method?
11-28-2012 03:59 AM - edited 11-28-2012 04:01 AM
<html> <head> <script>
$('#pagMenu').live('pagebeforecreate',function(event){setTimeout(function () {trapForBackKey();}, 200);});
</script> <script> function trapForBackKey(){ blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK,function(){alert('back event trapped3');}); } </script> </head> <body> <div id="pagMenu" data-role="page"> [...] </div> </body> </html> Other thing I tryed, without result. Both ways are working on Crhome webworks simulator. <body> <script> blackberry.system.event.onHardwareKey(blackberry.s ystem.event.KEY_BACK,function(){alert('back event trapped3');}); </script> <div id="pagMenu" data-role="page"> [...] </div> </body>
11-28-2012 07:55 AM
Try this....
<html>
<head>
<script>
$('#pagMenu').live('pagebeforecreate',function(eve
</script>
<script>
function trapForBackKey(){
blackberry.system.event.onHardwareKey(blackberry.s
}
trapForBackKey();
</script>
</head>
<body>
<div id="pagMenu" data-role="page">
[...]
</div>
</body>
</html>
11-28-2012 09:41 AM - edited 11-28-2012 09:42 AM
Thank you for answering.
The problem was that I wasnt including this page (index.html) in the webworks package. The web is in a webserver and I put in the config.xml the content pointing to that webserver. Is this a bad practice? The problem of adding the web project to the package is that to make changes you have to make a whole update of the aplication instead of changing just the server.
Apart from this, now my problem is that with
blackberry.system.event.onHardwareKey(blackberry.system.event.KEY_BACK,function handleBack(){history.back();return false;});
When I press back in the first page the app doesnt close as I expected it to do. Is there a way to ask like
if (history.canGoBack()){
history.back()
}else{
exit();
}How is this controled in bb?
12-03-2012 03:15 AM
Does any body know?
12-03-2012 08:25 AM
If you're capturing the back button, and the user presses it from the first page (where they would expect the app to exit), you could do something like this:
Check the location.href. If it's index.html than exit, if not do something else. You'll need to manually check this if you're overriding the back button event.
if (location.href === 'index.html') {
blackberry.app.exit();
} else {
// do something else
}