The Connection to the server was unsuccessful(file:///android-asset/www/index.html)
is showing when i run my android application.
please let me know how to resolve this issue.
For latest Cordova (4+) this a setting in config.xml:
e.g.
<preference name="LoadUrlTimeoutValue" value="70000"/>
Increases default timeout to 70 seconds (default is 20), reducing the chance of timing out.
Docs: https://cordova.apache.org/docs/en/latest/config_ref/index.html#preference
When loading a page, the amount of time to wait before throwing a
timeout error.
This may asked here many times..
This issue can fix by adding a timeout to the webview call (index.html). In your project_name.java class just add this
super.setIntegerProperty("loadUrlTimeoutValue", 5000);
And in Cordova latest, just use this to timeout
super.loadUrl(Config.getStartUrl(), 5000);
Also go through these so questions
Question1
Question2
UPDATE :
One more solution, try this
Create a main.html and put your code there, and in your index.html just redirect to main.html
<script>
window.location='./main.html';
</script>
This blog post from Robert Kehoe:
Seemed to be EASY to me
Made sense to me
WORKED for me
Rename your index.html to "main.html"
Create a new "index.html" and put the following content into it:
<!doctype html>
<html>
<head>
<title>the title</title>
<script>
window.location='./main.html';
</script>
<body>
</body>
</html>
Rebuild your app! No more errors!
Robert also said,
Another good idea is to give your application a “splash screen”, so that the user gets instant feedback that your app is loading/working, before it is fully ready.
The main problem for this issue is take more time to load your page.
yes it's can a hack to solve this issue, make a html page name
index.html and your existing index page name to be change as a
main.html or any other one give a redirection to this page like this
<script>
window.location='main.html';
</script>
am sure it's work very much
hey i think this error may come load multiple script in starting time so it will take more time.
so you set like this in your java...
super.loadUrl("file:///android_asset/www/index.html");
super.setIntegerProperty("loadUrlTimeoutValue", 600000);
reference1
reference2
Related
I have one cordova app that loads content directly from client website.I have used it like <content src="https://example.com/ios/index.html"> in config.xml file.I have used the splashscreen delay of 6 seconds.and the issue is when the splash screen hides shows the black screen for 5-10 seconds and after that client website content is shown.and also sometimes i am getting the error CONNECTION TO SERVER WAS UNSUCCESSFULL.I have also specified <preference name="loadUrlTimeoutValue" value="700000" /> but still having same issue.Anyone having the same issue for cordova ios and android app?can anyone help me with this issue.
You shouldn't do it like that. Now I don't want to play this script where you ask A and I tell you to do B, don't worry, but it's really not the way you should do it.
You should make cordova load an index.html which loads a javascript file cordova.js. You don't need to actually have it, the js file will be included when you compile the app.
Then you should add the whitelist plugin in case you don't already it, in order for your website to load correctly. https://www.npmjs.com/package/cordova-plugin-whitelist
You should disable auto-hide for the splashscreen in config.xml like so:
<preference name="AutoHideSplashScreen" value="false" />
You should then make the javascript load a fullscreen iframe with your website like so, then detect when loading has finished: (This should go into your index.html, in the cordova app)
<html>
<head>
<title></title>
</head>
<body>
<iframe id='frameid' onload='iframeLoaded();' src='https://mywebsite.com/mypage.html' style='border: 0; width: 100%; height: 100%'>Your browser doesn't support iFrames.</iframe>
<script src='cordova.js'></script>
<script>
iframe = document.getElementById("frameid");
iframe = document.getElementById("frameid");
function ready(callback){
// in case the document is already rendered
if (iframe.readyState!='loading') callback();
// modern browsers
else if (iframe.addEventListener) iframe.addEventListener('DOMContentLoaded', callback);
// IE <= 8
else document.attachEvent('onreadystatechange', function(){
if (iframe.readyState=='complete') callback();
});
}
ready(function(){
setTimeout(function(){
navigator.splashscreen.hide();
},555)
});
</script>
</body>
</html>
I haven't used cordova for a few months but that's how I did it if I didn't forget anything - Hoping I didn't... I didn't have time to test this, but you get the gist:
App start
Show Splashscreen
Load Index.html with Iframe in fullscreen pointing to https website.
Wait for iframe to finish loading.
Close splashscreen
Tell me if you run into any issue and I can help you further.
I do articles on blogs, but I want to know if this code can be simplified so that the page is faster without affecting other things
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- easd descargas texto -->
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-xxxxxxxx" data-ad-slot="xxxxxxxxx" data-ad-format="link" data-full-width-responsive="true"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
Try wrapping it in window.addEventListener("DOMContentLoaded", () => {...});, which will wait for the HTML to load before executing that piece of JS.
There still might be a bit of lag while the advertisements load, but there's not much you can do as that depends on the advertisement. You're letting other code run on your site, so you have no control over what it is, only when it is loaded.
I want to render a remote HTML page when my Cordova app starts, instead of "./index.html"
Tried this in config.xml
<content src="http://example.com/index.html" />
<access origin="*" />
And also tried placing this into ./index.html
window.location.href = 'http://example.com/index.html';
Both load a blank white screen when I start the app. Got no errors in the device log. Using Cordova version 5.3.3.
Any ideas?
If you want to use <access origin="*" /> you need to add this meta tag to your html page(s) in your cordova app:
<meta http-equiv="Content-Security-Policy" content="*">
I hope this helps you!
In your index.html page, you can write windows.onload() function inside this write redirect to this http://example.com/index.html
You can change the loadUrl statement in the native code e.g. in Android, you need to find MainActivity.java under platforms/android/src....
I myself am currently looking for a way to do this from index.html (to display for e.g. a loading screen / error message in case of network issues).
I believe I had tried using window.location.href but that simply opened the browser to the specified URL. I want it to open up in the app's WebView of course.
I got one strange behavior from JQM page.
I am using phonegap-android 4.4.2 with eclipse IDE.
Page code :
<html>
<head></head>
<body>
<div data-role="page" id="folfirstForm" data-dom-cache="true">
<link rel="stylesheet" href="../../css/follow_up.css">
<script src="../../js/addProdLine.js"></script>
<script type="text/javascript">
$(document).off("pageshow", "#folfirstForm").on("pageshow", "#folfirstForm", function() {
alert("First form loaded!");
AddElement();
});
</script>
----Some body----
</body>
</div>
</div>
</html>
You can see on code that I have put data-dom-cache="true" as per my requirement. I have also include the js file named as addProdLine.js which contains functions that i required, (for e.g. The AddElement() is from include file it self).
Now, when i am visiting this page first time all the functionality works very well. On second visit on same page I am getting the previous state of form which is expected as i have put data-dom-cache="true". But Might be due to data-dom-cache="true" my external js files are not being loaded on the second time visit on same page. I want, that on every visit ,my js file should run.
Jquery mobile only loads tag once when whole document is loaded. After the document is loaded if you will click on other links then only content part data-role=page will be refreshed through ajax along with data transition effect. Hence either add all your js script in a file and add it into head tag or stop loading other pages through ajax using following option:
<a href="#" data-ajax=”false”>Without Ajax</a>
But if you will disable content loading using ajax then link will work as it works in normal webpage and also transition effect will be not exist.
Edit:
One Alternate way could be: you can append some random values to the path of your JS files.
<script src="../../js/addProdLine.js?Q=<?php echo time(); ?>"></script>
Thank you for considering this post.I have a html file of containing lot of math formulas in single page, as shown below
<p id="p006_002"><span class="class_a">a</span> <math><mrow><mn>7</mn><mi>x</mi><mo>−</mo><mn>4</mn><mo>=</mo><mn>17</mn></mrow></math></p> <p id="p007_002"><span class="blue-no">b</span>
<math display='inline'><mrow><mfrac><mrow><mn>3</mn><mi>x</mi><mo>−</mo><mn>2</mn></mrow><mn>4</mn></mfrac><mo>+</mo><mn>5</mn><mo>=</mo><mn>1</mn></mrow></math></p>
<math display='inline'><mrow><mn>2</mn><mrow><mo>(</mo><mrow><mfrac><mrow><mn>4</mn><mi>x</mi></mrow><mn>5</mn></mfrac><mo>−</mo><mn>1</mn></mrow><mo>)</mo></mrow><mo>=</mo><mn>6</mn></mrow></math> </p>
The Mathjax link is provided as
<script type="text/javascript" src="mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
In Android Android 4.2.2 , When i use WebView.loadUrl("file"), MathJax get loaded , and formula getting generated, But When I use
WebView.loadDataWithBaseUrl("baseurl","file as string","text/html","utf-8");
Forumala fails to get rendered.I want these things to get work from Android 4.0.3.Please Help me to Solve this issue.Thank you
I found out a solution. But updating it so late. It may help others to solve this problem, if they are facing it in future.
For loading Inline mathjax with webview's loadDataWithBaseUrl .I have replaced all the file(css,js) etc references as complete path(example: "file:///),and I loaded html as
Webview.loadDataBaseWithUrl("http://bar","file:///<file path>","text/html","utf-8);
It is necessary to call mathJax on page finish.