[jbosstools-issues] [JBoss JIRA] (JBIDE-15790) Adding backbutton listener disables backbutton functionality for all pages
Ilya Buziuk (JIRA)
jira-events at lists.jboss.org
Tue Oct 29 13:26:02 EDT 2013
[ https://issues.jboss.org/browse/JBIDE-15790?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12825604#comment-12825604 ]
Ilya Buziuk edited comment on JBIDE-15790 at 10/29/13 1:24 PM:
---------------------------------------------------------------
I think it's not a bug. If you run your code on the device the result will be the same. Assuming that it's not a single page application the back button listener should be added on other pages. Here is the sample that works on both CordovaSim and device:
{code:title=index.html|borderStyle=solid}
<!DOCTYPE html>
<html>
<head>
<title>Back Button Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available
//
function onDeviceReady() {
document.addEventListener("backbutton", function(e) {
alert("backbutton event was fired");
}, false);
}
</script>
</head>
<body onload="onLoad()">
<button onclick="window.location = 'index2.html'">go to another page </button>
</body>
</html>
{code}
{code:title=index2.html|borderStyle=solid}
<!DOCTYPE html>
<html>
<head>
<title>Back Button Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available
//
function onDeviceReady() {
document.addEventListener("backbutton", function(e) {
window.history.back();
}, false);
}
</script>
</head>
<body onload="onLoad()">
<h1>Second file</h1>
</body>
</html>
{code}
However I've found that "navigator.app.backHistory()" (in the sample above "window.history.back()" is used instead ) doesn't work in CordovaSim. So I've created the separate issue JBIDE-15814
was (Author: ibuziuk):
I think it's not a bug. If you run your code on the device the result will be the same. Assuming that it's not a single page application the back button listener should be added on other pages. Here is the sample that works on both CordovaSim and device:
{code:title=index.html|borderStyle=solid}
<!DOCTYPE html>
<html>
<head>
<title>Back Button Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available
//
function onDeviceReady() {
document.addEventListener("backbutton", function(e) {
alert("backbutton event was fired");
}, false);
}
</script>
</head>
<body onload="onLoad()">
<button onclick="window.location = 'index2.html'">go to another page </button>
</body>
</html>
{code}
{code:title=index2.html|borderStyle=solid}
<!DOCTYPE html>
<html>
<head>
<title>Back Button Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available
//
function onDeviceReady() {
document.addEventListener("backbutton", function(e) {
window.history.back();
}, false);
}
</script>
</head>
<body onload="onLoad()">
<h1>Second file</h1>
</body>
</html>
{code}
However, I've found that "navigator.app.backHistory()" (in the sample above "window.history.back()" is used instead ) doesn't work in CordovaSim. So I've created the separate issue JBIDE-15814
> Adding backbutton listener disables backbutton functionality for all pages
> --------------------------------------------------------------------------
>
> Key: JBIDE-15790
> URL: https://issues.jboss.org/browse/JBIDE-15790
> Project: Tools (JBoss Tools)
> Issue Type: Bug
> Components: browsersim
> Affects Versions: 4.1.1.Beta1
> Environment: JBT 4.1.1 Beta1-v20131020-0207-B454
> Reporter: Vlado Pakan
> Assignee: Ilya Buziuk
> Fix For: 4.1.1.CR1
>
>
> 1. Create new Hybrid Mobile Project
> 2. Add HTML page defining backbutton listener and link this page from index.html
> {noformat}
> <!DOCTYPE html>
> <html>
> <head>
> <title>Back Button Example</title>
> <script type="text/javascript" charset="utf-8" src="cordova.js"></script>
> <script type="text/javascript" charset="utf-8">
> // Wait for device API libraries to load
> //
> function onLoad() {
> document.addEventListener("deviceready", onDeviceReady, false);
> }
> // device APIs are available
> //
> function onDeviceReady() {
> // Register the event listener
> document.addEventListener("backbutton", onBackKeyDown, false);
> }
> // Handle the back button
> //
> function onBackKeyDown() {
> alert('backbutton event fired');
> }
> </script>
> </head>
> <body onload="onLoad()">
> </body>
> </html>
> {noformat}
> 3. Add another HTML page and link it from index.html
> 4. Run project in CordovaSim
> 5. Navigate to page without backbutton listener and choose button Back
> ASSERT: Button back works index.html page is displayed
> 6. Navigate to page with buttonback listener
> 7. Choose button Back
> ASSERT: Alert box is displayed and no navigation to index.html happened
> 8. Open index.html page using address bar of CordovaSim
> 9. Navigate to page without backbutton listener and choose button Back
> ERROR: Nothing happened
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jbosstools-issues
mailing list