Reputation: 49
I want to open a website url when someone clicks the app icons i.e opens the app.
I tried something like this but no luck.
<script src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
function onLoad() {
document.addEventListener('deviceready', this.onDeviceReady, false);
}
function onDeviceReady() {
window.open("http://mywebsite.com");
}
</script>
</head>
<body onload="onLoad()"></body>
Any help ?
Upvotes: 1
Views: 760
Reputation: 53361
You have to configure the whitelist to allow your app to navigate to that site.
You can do it by adding this line to your config.xml
<allow-navigation href="http://mywebsite.com" />
or this one if you want to allow the navigation to all the urls on yourdomain.com
<allow-navigation href="http://mywebsite.com/*" />
Upvotes: 1
Reputation: 1861
You can Load your website to the app using Jquery load() or by Ajax or by InApp browser.
If you want to show your website to a div, you can do it by load() or by ajax call
HTML:
<div id="Load"></div>
<hr/>
<div id="ajax"></div>
JS:
/*Using Jquery Load()*/
$('#Load').load('http://apache.org');
/*Using ajax*/
$.ajax({
dataType:'html',
url:'http://apache.org',
success:function(data) {
$('#ajax').html($(data).children());
}
});
OR by Inapp browser
//using device ready
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
window.open = cordova.InAppBrowser.open;
window.open('http://apache.org','_self');
}
//simple code
var ref = cordova.InAppBrowser.open('http://apache.org', '_self');
Before using inappbrowser you must install the plugin to your project To add inappbrowser to project by commanline
$ cordova plugin add cordova-plugin-inappbrowser
Upvotes: 0