You can use inappbrowser cordova plugin.
Here is example of code:
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
window.open('http://paypal.me/xxxzzzyyy/5', '_blank', 'location=yes');
}
</script>
You can also call link onclick and there is close button which makes you back to app.
Answer from proofzy on Stack Overflowjavascript - Window.open + Mobile Devices + Canvas == Not working? - Stack Overflow
Open a new window (Popup) javascript in android - Stack Overflow
android - webview don't display javascript windows.open() - Stack Overflow
how to open mobile chrome browser with javascript or html - Stack Overflow
First of all, you need to set the following settings on your WebView:
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setSupportMultipleWindows(true);
Then you need to attach a WebChromeClient that overrides onCreateWindow. Your implementation of this method can create a new web view, and display it inside a dialog:
webView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
WebView newWebView = new WebView(MyActivity.this);
WebSettings webSettings = newWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
// Other configuration comes here, such as setting the WebViewClient
final Dialog dialog = new Dialog(MyActivity.this);
dialog.setContentView(newWebView);
dialog.show();
newWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onCloseWindow(WebView window) {
dialog.dismiss();
}
});
((WebView.WebViewTransport)resultMsg.obj).setWebView(newWebView);
resultMsg.sendToTarget();
return true;
}
});
Don't forget to set the new web view to the resultMsg, send it to its target and return true, as mentioned in the API documentation.
Please check with adding this -
getSettings().setSupportMultipleWindows(true);
For Android:
<a href="intent:https://yourwebsite.com#Intent;end" target="_blank">Open Browser</a>
Note: This solution will open default browser (if its set, if no default browser set, it will show list of browsers which supports opening url)
Make sure that, the click is generated by user (Not Javascript) to test this. Some browsers wont open if its NOT called by user.
I was looking for the answer too as I've tried to send my users from unsupported browsers (for ex: Facebook browser) to chrome.
Unfortunately, John's solution didn't work for me but it pointed in the right direction.
What works for me:
<a href="intent://mysite.com#Intent;scheme=https;package=com.android.chrome;end">
Click to open on Chrome
</a>
Explanation
I've found a good explanation at https://branch.io/glossary/chrome-intents/ , but to sum it up:
Split it to 3 vars:
URI: the name of the site (ex: google.com), and notice its without the UriSchemes.
UriSchemes: HTTP / https (you can read more about it at https://www.w3.org/wiki/UriSchemes)
PACKAGE: the package of the app we want to send the intent to, in our case its com.android.chrome
now you can just insert them in the code below
<a href="intent://URI#Intent;scheme=UriSchemes;package=PACKAGE">
Click to open on Chrome
</a>
I've been working on a passion project for a while. Here's the essentials of what I'm doing:
Get user input with several fields.
User checks one/more checkbox(es) to choose from several page templates.
User clicks "Generate" button.
Javascript determines which templates were selected, adds the user's input values to new HTML for each one.
Javascript window.open to create a new browser tab for each selected template.
Javascript document.write to write the completed HTML for each new tab, so user can save or print the results in that template format.
It works beautifully in desktop browsers (as long as the user allows pop-ups for the new tabs), but not so much in Safari or Chrome on iOS. Both of them successfully open the new tabs, but they either fail to write the new HTML to the documents, or they fail to display it. Either way, the result is new tabs with no content shown whatsoever. I haven't tested in Android browsers yet.
Is there something about iOS/mobile browsers that prevent new content from being written/displayed in new tabs? Or am I missing something else?
Whenever I tried to use window.open(url, "_blank", "popup"); to open a little arc window or something similar, it always ended up creating a new full-screen tab instead.
I really wish there was a way to open a compact window using a JavaScript API.