Closing a mobile browser tab with javascript
Solution 1
Setup a custom URI handler (for Android and for iOS). Then all you have to do is redirect to a URL that matches, perhaps using window.location
.
Solution 2
It seems that there are security restrictions that wouldn't allow you to close the window via JavaScript. See here
EDIT: You basically have two options: implement a custom URL handler for each platform you're developing for; or embedding a web view into your application (UIWebView for iOS or WebView for Android).
Manuel Martinez
Updated on June 04, 2022Comments
-
Manuel Martinez almost 2 years
I need a native app to fire a browser with some URL that will take the user to a mobile website. Inside the mobile website, there has to be a button that closes the browser (or sends any signal to the native app) so that the user gets back to the native app. Currently I'm trying to close the window, but I don't think that's gonna do the trick in all mobile devices.
My code:
$( document ).bind('pageinit', function(){ $.mobile.activePage.find('#close').click(function(){ window.open('', '_self', ''); window.close(); }); });
I'm using jQuery mobile.