jQuery Mobile programmatically reinitializes / restarts the application

I am writing an application with a phone and jquery mobile.

To handle unknown errors, I need to completely restart my application and reinitialize all variables and dynamic content back to be equivalent to the first run.

Initially, I just used $ .mobile.changePage ($ '# home'), which obviously does not work because it does not reinitialize any dynamic content or variables, so I get double ups.

Is there a way I can call in jQuery mobile to completely restart the application and return all the original settings?

+6
source share
4 answers

For a complete solution, I think you're out of luck.

iOS will definitely * DO NOT allow software killing of an application, not to mention a software launch.

Android really allows you to kill the application. Despite the undocumented ones (which I could find), you can use

navigator.app.exitApp ();

to kill the current application.

However, you still cannot restart it programmatically.

I think it would be best to write the reset code to variables and local storage / DB (if used). Then reload the index page through document.location.href = 'index.html?var=xxx'; where xxx = current timestamp. Placing a timestamp at the end ensures that it pulls out a non-cached version of the page.

* Edit: Added not to my Apple statement about killing an application, as it should be.

+8
source

Try document.location.href

 document.location.href = 'index.html'; 
+4
source

Have you tried to reload the application?

The reload () method is used to reload the current document.
The reload () method does the same as the reload button in your browser.
By default, the reload () method reloads from the cache, but you can force the reload to get the page from the server by setting forceGet to true.

 location.reload(); 
+2
source

Instead of restarting the application, you can check for the presence of a specific page on the page and configure what you want. so every time you visit this page, the values ​​will be initialized.

 $.mobile.changePage( "#PageID", { reverse: false, changeHash: false }); $(document).on('pagebeforeshow','#PageID',function(){ /* Intialise all your variables here*/ }); 
0
source

Source: https://habr.com/ru/post/953524/


All Articles