Close App JavaScript API
Close your Android or iOS app instantly using the WebToNative JavaScript API. Simple integration with Plain JavaScript and ES6 support.
Closes the app entirely the same result as the user quitting it from the OS app switcher. Use it to back a "Log Out & Exit" button in your website, end a kiosk-mode session, or let users leave the app from a menu instead of the hardware/gesture back action.
You'll need to import the javascript file in your website before starting from this link.
Platform support: Android and iOS.
JavaScript API Reference
closeApp
Immediately closes the app. Takes no parameters and has no callback, there's nothing to configure and nothing to read back.
window.WTN.closeApp();import { closeApp } from "webtonative";
closeApp();This call cannot be cancelled or confirmed after the fact. The app closes the instant it runs, with no native "Are you sure?" prompt. If you want the user to confirm first, gate the call behind your own confirmation UI, see Common Patterns below.
Common Patterns
Confirm Before Closing
Since closeApp doesn't show any confirmation of its own, ask the user first with your own dialog and only call it once they agree. Replace the window.confirm below with your own modal if you don't want the plain browser dialog.
function handleExitButtonClick() {
const confirmed = window.confirm("Are you sure you want to exit the app?");
if (confirmed) {
window.WTN.closeApp();
}
}import { closeApp } from "webtonative";
function handleExitButtonClick() {
const confirmed = window.confirm("Are you sure you want to exit the app?");
if (confirmed) {
closeApp();
}
}Closing After an Action Completes
If closing is the last step of a flow for example, logging the user out on your server first call closeApp only after that work finishes, so it isn't left half-done when the app quits.
Frequently Asked Questions
Notes:
closeApptakes no parameters and has no callback, there's no response to check for success or failure.
Feature taken live on 05/10/2023.
Last updated