Is there a way to refresh your phonegap application - eg, build the page and start running the scripts from the beginning?

跟風遠走 提交于 2019-12-21 07:15:28

问题


Is there any way to do this?

E.g., if a user starts the app with no internet connection, no remote scripts can be loaded, and the application basically can't run and I display a "No internet" page. But if the user gets internet later and the application is still running, is there any way to just "restart" ?


回答1:


how about -

document.location = "index.html"

PhoneGap applications are just like an embedded website - you should be able to go to any hyperlink you wish (mind the whitelists).

Of course, if you also want to detect when it's again online, you should use the PhoneGap Network API to bind to those online/offline events.

In general thought, have you ever thought of using the HTML5 manifest functionality to actually let your local PhoneGap app cache those remote scripts? That way your app could still run, even when offline (except if it needs remote data to "do your thing")...

Hope this helps!




回答2:


Try this

navigator.app.loadUrl("file:///android_asset/www/index.html", {wait:2000,  loadingDialog:"Wait,Loading App", loadUrlTimeoutValue: 60000});



回答3:


Accepted solution works, but might fail if you have an SPA with html5 url routing.

Here's a safest solution:

// keep startup url (in case your app is an SPA with html5 url routing)
var initialHref = window.location.href;

function restartApplication() {
  // Show splash screen (useful if your app takes time to load) 
  navigator.splashscreen.show();
  // Reload original app url (ie your index.html file)
  window.location = initialHref;
}


来源:https://stackoverflow.com/questions/8498738/is-there-a-way-to-refresh-your-phonegap-application-eg-build-the-page-and-sta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!