I have angular single app page application website not cordova, ionic etc., pure javascript and when I enter to the link, I would like to prevent user from press back button. The user will be able to close the browser by pressing home button.
Is it possible in javascript?
Thanks.
You can try document.addEventListener('backbutton', function(e) {e.preventDefault();}) to disable the back button.
Related
my android app automatically load a specific form from a web page and at the moment the submit button open a confirm popup. I want to automatically "click ok" in the popup to continue to the next page from the form without the human interaction necessity.
I wanted to try using javascript to force the confirm() function to return true, but the function is hidden in the submitForm() function code.
Silly solution, trigger a click at a specified coordinate:
See https://stackoverflow.com/a/3277417/14406944 for reference.
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 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 have a page that is displayed in an UIWebView on an iPad app. The page has an input field, and when the user taps on it, the virtual keyboard popups up.
Currently, the keyboard has the blue 'Go' button. I would like to change the button text from 'Go' to 'Done' and I want to grey-out/disable the button until the user types in at least 1 char.
Is this possible with Javascript/jQuery mobile? I don't have access to the app.
Thanks.
I don't think this is possible. Bu you can change some functionality of the keyboard in html.
Make the button submit your form
Make another keyboard displayed
More features should not be available without access to the app. Instead of greying out the button, you can validate the form before submitting it with jQuery.