I am trying to create a mobile webapp using HTML5 and JqueryMobile. I want to use one Exit button on which the app should be exited. I already tried window.close() and self.close().
That is not working.
Or it will be okay...back button of device automatically handles the exit option of app?
Anyone have idea about this?
On Android you can use...
navigator.app.exitApp();
As far as I'm aware, iOS does not offer a way to programmatically exit an application.
But really, you don't need an exit button. The devices that the app will run on all have home and/or back buttons, which are the correct way to "exit" apps. Let the OS decide what to do with it, not the user.
Back button is used in navigation so it will just navigate you to previous page in your web view.
You need to handle it yourself in back button handler and call
navigator.app.exitApp()
when you need to exit app.
You can add back button handler with command:
document.addEventListener('backbutton', backbuttonHandler, false);
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
Is there any Cordova/DOM event that I can hook into on iOS when the user directly closes the app (by double-tapping the Home button and then swiping the app away)? The pause event does successfully fire when the Home button is pressed once and the app is sent to the background, but the double-tap+close seems not to do this -- at least in the emulator.
I am using the pause event to capture and store app state, so closing without saving will leave the user with no previous state to return to, or worse, an old state.
I am aware of the "iOS Quirks" warning in the documentation that says:
In the pause handler, any calls to the Cordova API or to native plugins that go through Objective-C do not work, along with any interactive calls, such as alerts or console.log(). They are only processed when the app resumes, on the next run loop.
...but unless someone corrects me, I don't think this is the issue here
This question has been asked a lot on ionic forum and the consensus at the moment appears to be that this is not possible. I had this same desire for a time keeping app. I ended up deciding to use setInterval at a frequency acceptable (for me 3 seconds was fine). Agree this should be a feature
I am making a Windows 10 Web App (Project Westminster). There is a page that requires user to input something, and there's a 'save' button, and another button that leads to another page of the app.
To prevent user clicking the wrong button and lost his/her data before saving, I implement the JavaScript confirm() method to ask users to confirm before leaving.
This is working on iOS, Android, or Edge browser on Windows 10, but not on the Windows 10 app. The prompt does not show up but the page also does not exit, as if the user has already pressed the "stay here" button.
How can I make this work as expected? Thanks!
Windows will not let you prevent the closing of an app of the user chooses to, so the best way to handle this would be to save the data on the Suspending event and load it again when the app resumes.
Here's a sample that might help you get going.
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.
I realized that iOS is not working on a form that you can close the application.
I work with PhoneGap version 2.2.0 and I do like to have my application exit button,
I thought about the possibility to move the app to the background and back to the iPhone home page when you click on the button to exit.
I did not find how to do it through PhoneGap
is there a way?
Take a look at this post: https://gamedev.stackexchange.com/questions/17709/can-an-ios-application-have-an-explicit-quit-button
It is quite possible, maybe even likely, that Apple will reject your app for doing this. It should be sufficient for users to close the app simply by pressing the home button.
UPDATE: Just because Android has a button for you to close the app does not mean that one is needed on the iOS version. As other posters have said, conventions are different between the two operating systems.
There is already a button to exit -- the home button on the device. You do not need to add one in your application.