I use an 3rd-party Oauth page in an in-app browser to login into my application. On successful login, I close the in-app browser using its close method and move to my home screen. But on Android back button press, it moves back to the in-app browser login page. I'm using Cordova's exit method to quit the app on the back button pressed event. But somewhere I read that I should avoid using the exit method, as it is not a good practice. Can't I close the in-app browser forever to avoid using the exit method to quit my app?
Make sure you're handling the backbutton cordova event. Instead of exiting the app, why not just disable navigation back to that page. On back button event check the route you're going to and if its that page disable it.
Related
Is it possible to check if the user is trying to exit the page on iPhone via Javascript?
So basically when the user swipes up the home button and the Browser Window is shown in the app gallery mode? Is there an event for that?
No there is not in my knowledge.
I don't think there is a way we can see if a person is trying to get out of a Javascript page in an iOS software.
I'm doing a PWA using Vue.js, i know that cordova can handle the android/iOS back button (the device back button, not the browser one), so it's ok.
How can i detect this on vuejs?
Device back button is native feature of Android/ios, so can not detect event on click.
Test Platform: Xcode iOS Simulator App (iPhone iOS 9.3)
Repro Steps:
Open a "webview" page with a form on the iOS app
Open safari JS console
Hit $("#myForm").submit() in the console
Form submit happens and user goes to next page
Hit back (or cancel) button on the app
User comes back to the cached page from history
Hit $("#myForm").submit() in the console again
Nothing happens!
Does iOS restrict submission of form "through javascript" multiple times on a cached page?
This seems to work if I "physically" click on the submit button but doesn't work through javascript.
What is going wrong here?
I've surveyed most of the questions on the web but this still gets me confused....
My question is, how to detect hide/leave event of a website tab in mobile phone browser, my situation is NOT about closing the tab(like pressing the X button at the up-right or up-left corner), and also NOT about closing the whole mobile browser app directly.
(Previously, I have a webpage with a websocket connected to receive the encoded audio content, and then use AudioContext to play the sound)
Below are the two situations I've encountered.
When I press the HOME button and the mobile browser app hides.
When I click a url in the Messenger app or Facebook app of my iPhone, and press the Back button to go back.
the url link is opened in the in-app browser which made by Facebook directly, and when I press the back button on the left-up corner, the view jumps back to the Messenger window or the Facebook timeline.
In these two cases, I have listened beforeunload (and also pagehide event for iOS), but neither one is catched. And I have found that the websocket connection is still connecting and the audio is still playing. It seems like the whole page is still running somewhere(but you cannot see). I also tried listening to a div :visible, but it is still giving me true when I pressed the home button or leave the facebook in-app browser.
Is there still any way to detect these two kinds of situation? I want to turn off the streaming sound and also close the websocket connection.
Just found the answer....
Page Visibility API https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API
Does Phonegap 3 includes a method "onExit" or "onDestroy" ? I would like to perform some actions before the app closes.
Basically, I want to kill an admob.
Well, after some exploration seems like phonegap api have no such event as onDestroy. This functionality could be implementat in some states for android, course a bit creepy, but in iOS this is not avalible anyway.
Android logic:
if user presses the home button app fires pause event, but application is not closed, so window.onunload will take no reaction. From this point phonegap app's webView doesn't recieve any event. But if user presses back button on first page or application was closed programmatically window.onunload must fire. I think there is a way to realise some kind of native callback by creating a java background process.
iOS logic:
In iOS, application can't close itself by some kind of apple sequrity statements. So app never closes untill user do this by double pressing the home button and killing the app. By some reasons apple dosen't allow apps do anything in background, excluding push notification recievement. So app can detect only it's transfer from foreground to background
I think all you have is onpause/onresume