Closing a mobile browser tab with javascript - javascript

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.

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.

Related

Prevent my website from opening in other mobile apps Web View

When user is using an app, Facebook's app for example and click on my website link, my site will be opened in Facebook's app Webview.
I want to prevent that and open it in a browser instead.
Can I make it work by adding some javascript codes to my website ?
Try window.open() method of Javascript.

How can I enable communication between ionic app and browser?

I am trying to make an app in ionic that can send message to browser in same device (android or ios) and receive response back from browser. Is it possible?
I am pretty sure that it is not possible to communicate with the native device browser to track which URL the user is visiting. However, using cordova-plugin-inappbrowser you can open a browser window inside your application and track URL changes.
By listening to events, either loadstart or loadstop you can see where the user is and retrieve the URL with something like this:
var browserRef = cordova.InAppBrowser.open('http://apache.org', '_blank', 'location=yes');
browserRef.addEventListener('loadstart', function(event) {
console.log(event.url);
});
You can find more information on this plugin here.

Android: Browser close "window"

I wrote a simple WebUI for Android/iPhone where users have an account with logout function. They usually start the application via a bookmark on their homescreen.
I want to give them a handy button to close the web browser/page once the logged out.
Whit the following script, the browser prevents the action
<script>
window.close();
</script>
Is there a workaround that specially works on Android (default browser)?
Used tools/techniques
Tomcat and JSP
jQuery Mobile (1.4.x)
Android 4.2.x with default browser
Bookmark on homescreen
If I understand your question correctly, you want to use script to close the browser window itself? If so, you should read about this:
http://www.javascript-coder.com/window-popup/javascript-window-close.phtml
You'll meet some security restrictions with the close() function call.

How to disable alt+tab in IE8 aspx web page

I am struggling in disable alt+tab in IE8 web browser page. my page is a show modal dialogue.
You can't. If you want that kind of control over the operating system you'll need to install local software.
If you don't want to port your whole application to native you can write a native helper app that responds to a custom url scheme and processes it accordingly, like
myPopover://title/description

Open non-whitelisted URLs in Cordova in ChildBrowser rather than main Webview

I'm trying to implement the official Twitter and Facebook share buttons in my Cordova/Phonegap app, and I'm running into major difficulties with them. Both of them attempt to load an iframe element to display their buttons, which works, but clicking either of them causes them to open in the Webview, with no way to open them instead in the ChildBrowser. This becomes an issue when the user is done sharing but can't go back to the app due to a lack of navigation buttons.
Is there some way to open a list of URLs in ChildBrowser by default instead of Webview?
Well you can use the:
ChildBrowser.showWebPage();
command to open non-white listed URL's.
Coming in 2.3.0 we will overload window.open() in so that you can specify whether or not you want the url opened in the main web view, the OS browser or the special in app browser that does not have access to the Cordova API.

Categories