在UWP中';getHostEnvironmentValue';通过JavaScript调用提供异常

在UWP中';getHostEnvironmentValue';通过JavaScript调用提供异常,uwp,uwp-xaml,Uwp,Uwp Xaml,在我的UWP项目中,我使用Javascript获取os sku值 MainWindows.xaml.cs: public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); //Load local html file using 'Navigate' method

在我的UWP项目中,我使用Javascript获取os sku值

MainWindows.xaml.cs:

    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            //Load local html file using 'Navigate' method    
            WebBrowserName.Navigate(new Uri("ms-appx-web:///HTMLPage1.html"));
            }

        async void WebBrowserName_ScriptNotify(object sender, NotifyEventArgs e)
        {
            if (e.Value.StartsWith("SomeValue"))
            {
                Windows.UI.Popups.MessageDialog dialog = new Windows.UI.Popups.MessageDialog("Calling javascript function from C#");
                await dialog.ShowAsync();   
            }
        }

        private  void Button1_Click(object sender, RoutedEventArgs e)
        {
                        WebBrowserName.InvokeScriptAsync("JSMethod", new string[] { "" });
        }

    }
<html>
<head>
    <script type="text/javaScript">
        function JSMethod() {
           external.getHostEnvironmentValue('os-sku'); //Exception Occured
        }
    </script>
</head>
<body>
    "OSSKU :
    <p id="demo">
        <script></script>
    </p>
</body>
</html>
和HTMLPage1.html:

    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            //Load local html file using 'Navigate' method    
            WebBrowserName.Navigate(new Uri("ms-appx-web:///HTMLPage1.html"));
            }

        async void WebBrowserName_ScriptNotify(object sender, NotifyEventArgs e)
        {
            if (e.Value.StartsWith("SomeValue"))
            {
                Windows.UI.Popups.MessageDialog dialog = new Windows.UI.Popups.MessageDialog("Calling javascript function from C#");
                await dialog.ShowAsync();   
            }
        }

        private  void Button1_Click(object sender, RoutedEventArgs e)
        {
                        WebBrowserName.InvokeScriptAsync("JSMethod", new string[] { "" });
        }

    }
<html>
<head>
    <script type="text/javaScript">
        function JSMethod() {
           external.getHostEnvironmentValue('os-sku'); //Exception Occured
        }
    </script>
</head>
<body>
    "OSSKU :
    <p id="demo">
        <script></script>
    </p>
</body>
</html>

函数JSMethod(){
external.getHostEnvironmentValue('os-sku');//发生异常
}
“奥斯库:

部署UWP应用程序后,在运行上述应用程序时,我得到, 异常

UWP 0x800a01b6-javascript运行时错误:对象不支持 属性或方法“gethostenvironmentvalue”

我不知道出了什么问题。

作为方法介绍,此方法仅在Microsoft Edge中可用。即使web view control将视图嵌入到使用Microsoft Edge渲染引擎渲染web内容的uwp应用程序中,但uwp与Edge不同,而且,uwp应用程序运行沙盒,它有更多的安全性和资源访问限制。因此,作为例外,此方法不能在UWP应用中使用,不受支持