I am working on an ionic framework based mobile application (mainly targeted for Android). My project is a tab based application. In the first tab I want to load an external website, but I can't figure it out how to do it.
I tried ngCordova InAppBrowser, but it takes full screen and my navigation tabs fall behind.
I also tried loading an iFrame and it works in simulator, but this solution do not work at all on android devices and show an empty iFrame (beside its positioning limits that I think I could sort it out using css).
Is there anything I am missing? Any suggestion?
The final app should looks like (Its native iOS version):
You need to use the target _self in create. target: The target in which to load the URL, an optional parameter that defaults to _self. (String) _self: Opens in the Cordova WebView if the URL is in the white list, otherwise it opens in the InAppBrowser. you need to add the urls in white list.
Selecting a Tab There are different ways you can select a specific tab from the tabs component. You can use the selectedIndex property to set the index on the <ion-tabs> element, or you can call select() from the Tabs instance after creation.
In order to link the ion-tab-button to the ion-tab container, a matching tab property should be set on each component. The ion-tab-button and ion-tab above are linked by the common tab property. The tab property identifies each tab, and it has to be unique within the ion-tabs .
Try to load the content from the website via ajax, not the whole page via iframe. You can achieve this by doing it like it follows:
You're first going to put a div to that place, where you want to page to be displayed.
HTML:
<div id="loadExternalURL"></div>
And in JavaScript you fetch the code via Ajax or jQuery and after you got it, you're going to fill the div with that code:
JS:
/*jQuery*/
$('#loadExternalURL').load('http://www.google.com');
/*ajax*/
$.ajax({
dataType:'html',
url:'http://www.google.com',
success:function(data) {
$('#ajax').html($(data).children());
}
});
I managed to solve it using iFrame.
Using ajax .load()
have problems like loading metadata. To use iFrame, you should add <access origin="yourwebsite.com/*"/>
. Also, you should change your Android MainActivity on Create like this (I can't find source source: iframe for Android apps using Phonegap not working):
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.init();
super.appView.setWebViewClient(new CordovaWebViewClient(this, super.appView) {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With