0
votes

This question was raised several times already. But I am still struggling with the issue with no idea how to solve it.

My very primitive app code:

<!DOCTYPE html>
<html>
<head>
<title>Standalone Example</title>

<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
var iabRef = null;

function onDeviceReady() {
  iabRef = window.open('http://example.com', '_blank', 'location=no', 'zoom=no', 'hardwareback=yes');
  iabRef.addEventListener('exit', iabClose);
}

function iabClose(event) {
 iabRef.removeEventListener('exit', iabClose);
}
</script>
</head>
<body>
</body>
</html>

On phonegap forum I read that Android hardware back button functionality was added by default. But it doesn't work for me, still.

desired behaviour: navigate through several links on a page, tap back and see previous pages, according to history.

actual behaviour: after navigating through several links and tapping back inAppBrowser is closed, I see white screen instead of a previous page.

As you can see I added hardwareback property also, but with no luck. Also I tried ti hijack back button behaviour with putting this code inside onDeviceReady function:

document.addEventListener("backbutton", function(e){
  e.preventDefault();
  navigator.app.backHistory()
}, false);

And again no luck. Tried on several different devices, all the same. I guess there is a very simple thing I am missing. Any ideas?

If it matters, I build the app on build.phonegap.com.

1
@daserge, do you mean with 'backbutton' event listener? If so, I just did it with no luck again. - Denis

1 Answers

0
votes

Problem was that I called IAB in a wrong way, it should be

iabRef = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');

Also I should have specified the source to npm for IAB plugin. Without this specification PGB uses old version from deprecated repo.