3

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.

Ry-
  • 218,210
  • 55
  • 464
  • 476
Manuel Martinez
  • 388
  • 1
  • 3
  • 13

3 Answers3

2

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.

Community
  • 1
  • 1
kabuko
  • 36,028
  • 10
  • 80
  • 93
1

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).

Ethan Reesor
  • 2,090
  • 1
  • 23
  • 40
0

On iOS if you launch Safari from your app you won't be able to get back to your app after Safari closes, unless your app is registered as a custom URL handler and the page you are on launches a URL that launches your app.

On iOS if instead of launching Safari you show the web page in a UIWebView you have control over exiting the page.

Gruntcakes
  • 37,738
  • 44
  • 184
  • 378