admin管理员组

文章数量:1327849

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.

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.

Share Improve this question edited Jun 7, 2012 at 0:53 Ry- 225k56 gold badges492 silver badges498 bronze badges asked Jun 7, 2012 at 0:47 Manuel MartinezManuel Martinez 3881 gold badge3 silver badges13 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 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.

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

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.

本文标签: jqueryClosing a mobile browser tab with javascriptStack Overflow