I'm currently working on a web application that I access through the PhoneGap AppBrowser for mobile devices. The challenge I'm facing is with the index.html page, which I use as a splash screen but later want to prevent users from revisiting after they've been redirected to the main application page using JavaScript.
I attempted to achieve this by using "window.location.replace("www.myapp.com");", but it opened the page in the system browser instead of the desired behavior. I also tried setting up an event handler for the back button press, but it didn't work properly when returning to the index.html page.
My confusion arises from not being sure if the application opens in the Cordova webview or the app browser. I experimented with changing parameters like '_self' and '_blank' in the code, but still encountered the same issue.
How can I guarantee that clicking the back button will exit the application rather than allowing users to return to the index.html page?
Currently, I am using Cordova CLI version 6.1.1 and testing on Android 5.x.
Below is the code snippet from index.js:
$(function () {
document.addEventListener('deviceready', onDeviceReady.bind(this), false);
function onDeviceReady() {
document.addEventListener("backbutton", onBackKeyDown, false);
var url = 'http://www.myapp.com';
window.open = cordova.InAppBrowser.open;
setTimeout(function () {
var ref = cordova.InAppBrowser.open(encodeURI(url), '_self', 'location=no');
}, 2500);
};
function onBackKeyDown(e) {
e.preventDefault();
console.log(document.location.href.indexOf('asset/www/index.html') > 1);
}
});