I want to be able to link to a webpage inside the phonegap webview that loads an external webpage inside the same phonegap webview. If I do this, it loads inside the webview:
public class App extends DroidGap {
#Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("http://google.com");
}
}
However, I want to have an internal page launched first, with a link to the external page, so I do this:
public class App extends DroidGap {
#Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
}
and I have a link:
Google
but this link launches google outside the app, in the web browser, instead of in the phonegap webview. What can I do to make sure the link to the external page is launched inside the app's phonegap webview?
Ahhh.. Found the answer on this question.
I had to add
<access origin="www.google.com"/>
to the phonegap.xml file.
This seems to have changed, and access origin seems to have no effect. If you're using the cordova whitelist plugin, as seems to be standard. You need to use allow-navigation in your config.xml file. Without this it will open your web browser.
<plugin name="cordova-plugin-whitelist" version="1"/>
<allow-navigation href="https://google.com/*" />
Then you can use window.location = 'https://google.com' to move to another webpage within your JS.
In the latest phonegab (1.7) in Cordova.plist there is a Key: OpenAllWhitelistURLsInWebView set this to YES.
Related
I'm using the standard Android SDK with Ecliple as provided from the Android website.
What I want to to is to have an activity display a WebView that loads a local HTML-file. Everything works fine until I try to load the webview.
I've placed all the index-files I've tried in the project's assets-folder.
This is the code in my activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webView = new WebView(this);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("file:///android_assets/www/index.html");
setContentView(webView);
}
When I run the app over ADB, I get the following message in the WebView:
Webpage not available
The webpage at file:///android_assets/www/index.html might be temporarily down or it may have moved permanently to a new web address.
I know this problem has been posted before, and I've tried every single solution out there. But it just won't load. It displays online http-addresses just fine, but it doesn't seem to find any of the local files.
Please help me, this drives me mad.
Change this line:
webView.loadUrl("file:///android_assets/www/index.html");
to this :
webView.loadUrl("file:///android_asset/www/index.html");
is android_asset not android_assets :D. Good Luck
hi I have Android App as I embed HTML file , I added my code and when I test the app I noticed that some of css classes doesn't called as #media also the JQuery doesn't called .
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_elaraby_group);
WebView wv=(WebView) findViewById(R.id.web_engine);
wv.loadUrl("file:///android_asset/index.html");
}
Well you have to provide exact same structure you are using in html page in your asses folder.Otherwise it will not get some files referenced in your html file.And hence those CSS and JavaScript code never gets run.So try with providing same structure as your localhost server.
I'm using cordova webview to wrap my live online webapp.
And I need to set a background for the cordova webview.
Apparently, specifying android:background attribute won't work on cordova webview.
So I'm looking for a way to set a background for cordova webview.
Packaging in either pictures or webpage are OK for me.
Here is a related question I just asked. And as suggested in the answer, I can use the cache to load the webpage in advance. However it is done in runtime. What I need now is to burn the background, or cache into the app.
Try using a Cordova splash screen. The API is here: http://docs.phonegap.com/en/edge/cordova_splashscreen_splashscreen.md.html#Splashscreen
public class splashScreen extends DroidGap
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//super.loadUrl("file:///android_asset/www/index.html");
super.setIntegerProperty("splashscreen", R.drawable.splash);
super.loadUrl("http://www.google.com",10000);
}
}
Make sure that you create a splash.png image and save it in your /res/drawable/ folder.
This should have the effect of displaying a "background" on the WebView while your external URL loads, instead of just showing a black screen.
i am building a phonegap(v1.3) android(for 3.1 sdk) app. i load the index.html page as in the sample app
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setIntegerProperty("loadUrlTimeoutValue", 60000);
super.loadUrl("file:///android_asset/www/index.html");
}
this works fine. now later on i want to load another abc.html file in the webview when i call for it from the js through a plugin. How to achieve a function like this which we can call from a Phonegap plugin.
public void loadUrl(String file){
super.setIntegerProperty("loadUrlTimeoutValue", 60000);
super.loadUrl("file:///android_asset/www/"+file+".html");
}
Or if not this way, how to load another html in the phonegap webview?
a simple
window.location.href = "file.html";
was the way. :(
OK. Have been trying for two weeks to get a simple web page I created in FrontPage (test.htm) to load into my Activity in my Eclipse Emulator. I have placed my page (test.htm) into my 'assets' folder and created the VERY simple code below. I STILL cannot get the page to load into my Emulator. I am using an XML with WebView within a Linear Layout (myxmlfile). Does anybody see anything blatantly wrong?? I have also tried: file:///asset/test.htm but my assets folder is asset(s) with an 's'.
public class Activity5 extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.myxmlfile);
WebView x = (WebView) findViewById(R.id.webview);
x.loadUrl("file:///assets/test.htm");
}
}
Please HELP!
Do you have to add this uses permission
<uses-permission android:name="android.permission.INTERNET"/>
into your AndroidManifest.xml ?
I think your html path is not correct. It must be android_asset instead of asset:
x.loadUrl("file:///android_asset/test.htm");