I am using PhoneGap 2.9 on a Galaxy S3 Android 4.2.1 to develop an application. In the application i have overridden the default back button behavior. The back behavior is simply a call to :
window.history.back();
I have 4 html pages. After navigating all the way to page4.html, I hit the back button and successfully navigate to page3.html. On page3.html I must hit the back button twice in order to successfully navigate to page2.html. It seems to behave this way regardless of the navigation plot. The first "back" works fine, all subsequent ones require a double tap of the back button.
Stangely, when I put an alert("going back!") just before the call to window.history.back(),it displays properly for every "back" tap in the navigation. What could be causing this?
I'm not exactly sure how you are calling window.history.back() but you could do something like this:
$("#backButton").bind("click", backClicked);
function backClicked(){
window.history.back();
}
and I highly recommend incorporating the fastclick.js library to any project that you want responsive buttons.
Related
I am working on a PWA and I have a page with a full screen modal in it, which pops up upon a button click to perform a specific action.
On the modal I have a close button tied to a function which works fine in closing the modal. However I noticed that on most native apps, when a modal is active clicking the (android) back button in a UI like mine closes the modal instead of going to the previous view.
My concern is if it were possible to listen to the android back button being clicked, prevent the default action and call another action. Or if there's anyway else around this!
I've made researches but all I can see is handling the browser back button, which in my case does not work. Tested on samsung A30,S10,A50.
From the Suggested question which I had gone through, There's no answer concerning how to handle the back button, Only on how to intercept it. And none of those answers my question.
Kindly note, PWA is already installed, hence in standalone mode
There is no way to handle the back button of Android in the PWA environment.
It is a system button which "clicks" the history.back() of an open browser. If there is no back-history it closes the browser.
But it doesn't know anything about this special button. There would be the need for something like the keypress-events. But there is no standard and so no implementation in the browsers.
The only way to handle this stuff in your app, is to manage the history.state in your app.
Push a new state with opening the modal. And close the modal in the popstate-event.
https://developer.mozilla.org/en-US/docs/Web/API/History_API/Working_with_the_History_API
I developing a app using phoneGap and jQueryMobile. For this I am using in app browser. Its work properly except one issue. when I open app it goes to login page. After login I click mobile back button it goes to login page but it should not happen. similarly if I browse multiple pages and want to exit then it moves one by one pages so its not close my app by clicking single back button.
So to fix this issue i used hashcode in url. Now it disable back button but my jQueryMobile pop not working because its work on hash in url.
Please suggest how to fix this.
Either suggest a method to disable back button without using hash code or open popup if hashcode used.
To disable hard backbutton use the following code
document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown(e) {
e.preventDefault();
}
Or you can do page back navigation in OnBackKeyDown method as follows
function onBackKeyDown(e) {
history.go(-1);
navigator.app.backHistory();
}
I am using jquery mobile in a cordova app.
I have multiple links (jquery mobile buttons), some of which follow a normal href link, others call some code in onclick.
When pressing my buttons making use of onclick, they work for multiple presses . I can press them multiple times, each time envoking the code.
However, when I press on of my buttons with a normal href link, my buttons making use of onclick seems to break. The moment I press a button following a normal href link, my other onclick buttons stop working.
It is worth noting that my buttons making use of onclick, also NEVER shows the "pressed" animation that jquery mobile adds when clicked. The normal href buttons ALWAYS shows the "pressed" animation when clicked.
My links all navigate to outside of the app, either activating an intent, or navigating to an external website using InAppBrowser. The normal href buttons always works.
I have tried to reload the page in place when a button is clicked, but this does not work.
$("#ctel").on('click', function (e) {
$.mobile.changePage("#businessCard");
});
My links:
As #Sithys was suggesting, I actually did have an error not relating directly to the jquery mobile buttons. I was re-writing my url's to point to another stats url, from which it then redirected to the appropriate url.
It seems some of the intents did not like this redirect, and probably caused an undesired effect/error somewhere in the android/cordova eco system. I removed the stats url, and by implication the redirect to the intent, and all is working as it should.
Strangely, I did however test this in Ripple emulator, and there it works perfectly fine with the stats tracking url and redirect.
I ended up doing a manual ajax post to track my clicks, and just activated the intents as per normal.
This seems like a simple fix, but I can't find any information!
Our mobile site in Safari has been sporatically displaying a dialog saying 'Open this page in "App Store"?' with a cancel and open button, both of which dismiss the dialog but don't do anything beyond that. This dialog doesn't come up all the time, but we have nothing explicitly calling this dialog and want this gone.
We do have a smart banner for our app. We also have 2 buttons in our site source to download/open the app from the page, which links with a specific appstore URL. I have a feeling this has something to do with this dialog but I don't know what.
Can anyone provide more information about this dialog? What can we do to prevent its appearance?
If it makes a difference, we're testing this mobile site with an iPad running iOS 7.
I've included this blurred out screen shot to focus on the unwanted dialog.
I got the same problem for IOS 9.0 and IOS 8.4 and after trying almost everything i found the solution. On click of button which shows this pop-up you must be doing some asynchronous call and on getting the response if you do window.open(someUrl) you will always get this pop-up. You can solve this by making that call sync or get the url even before click on the button and just do window.open with that url. I changed my call to sync this issue is solved.
I have experienced such a weird behaviour from titanium project using alloy that runs on android. I created a new window and then link it to another. like in android when you click button on activity 1 it refer to activity 2. when i click back button it back to activity1 (in android). But in alloy, when i pressed back, no matter on windows i'm in, it always back to home. Not back to the first window (or before it). How can i do such a thing in alloy to get the back button result same like in android.
activity1>>activity2>>activity3>>activity4
when you pressed back button it should back to activity3, but in alloy its just back to home.
If someone know how to achieve that (same like in android). Or simple example would be better.
NOTE: it solved using classic mode. i'm confused using the mvc one.
Write this piece of code when the window loads:
win.addEventListener('android:back', function(e) {
console.log("Pressing Back Will Not Close The Activity/Window");
win.close();
});