简体   繁体   中英

How to restart Cordova WP8 app?

I have a WP8 Cordova app that has one page locally and then it redirects to a server for further functionality. Both pages have the cordova JS API's available and things work well.

Except that when I want to go to the local start page again. Any anchors to it (pointing to x-wmapp0:www/index.html ) do not work on the HTML side.

In addition, any tricks with plugins and invocations of CordovaBrowser.Navigate() result in UnauthorizedAccessException errors.

The fallback has been for me to try to go back in browser history like this:

window.history.go(-window.history.length + 1);

But this doesn't do anything if I spend any time in the remote pages at all. So this isn't applicable either!

Is there a decent way to get to the starting page? With help from C# or otherwise?

So the UnauthorizedAccessException stuff came from thread issues. (The VS Express for WP can sometimes hide the details of an exception pretty well.)

This is a complete plugin that performs the redirection with neatest elegance available.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

using WPCordovaClassLib.Cordova;
using WPCordovaClassLib.Cordova.Commands;

namespace Cordova.Extension.Commands
{
    public class Jumper : BaseCommand
    {
        /** Instruct the browser component to go to beginning. */
        public void goHome(string unused)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                var webview = WebViewHandler.getInstance().webView;
                webview.CordovaBrowser.Navigate(webview.StartPageUri);
            });
        }
    }
}

The WebViewHandler is a singleton for sharing the Cordova WebView to plugins, described in another SO answer (thanks @MikeBryant!).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM