iframe visual studio html5 windows 8 app

2019-07-27 08:00发布

问题:

I'm creating my first windows 8 app in metro style. I'm trying to do this with a iframe for runescape.

This is my code :

    <!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Runescape_Metro_Client</title>

    <!-- WinJS references -->
    <link href="//Microsoft.WinJS.2.0/css/ui-dark.css" rel="stylesheet" />
    <script src="//Microsoft.WinJS.2.0/js/base.js"></script>

    <!-- Runescape_Metro_Client references -->
    <link href="/css/default.css" rel="stylesheet" />
    <script src="/js/default.js"></script>
</head>
<body>
    <iframe sandbox="allow-scripts" id="Iframe" src="http://www.runescape.com/game" style="width:100%; height:100%"></iframe>
</body>
</html>

and this is the error i get :

APPHOST9625: Kan niet navigeren naar: 'http://www.runescape.com/game'. Een iframe heeft geprobeerd om naar een URI te navigeren die niet is opgenomen in de ApplicationContentUriRules voor deze app. Gebruik in plaats daarvan een x-ms-webview-element om de URI te bekijken of voeg de URI toe aan de ApplicationContentUriRules-sectie van het pakketmanifest, zodat het iframe daarnaartoe kan navigeren. (Voeg in Visual Studio deze URI toe aan het tabblad Content URIs van de Manifest Designer.)

(translated to english with google translate it is:

APPHOST9625: Can not navigate to: http://www.runescape.com/game. An iframe has tried to navigate that is not included in the ApplicationContentUriRules for this app. To a URI Instead, use an x-ms-webview element to see if the URI add the URI to the ApplicationContentUriRules section of the package manifest, so the iframe go there to navigate. (Write in Visual Studio this URI to the Content tab of the Manifest Designer URIs.)

Google didnt help so thats why i am asking it here.

回答1:

For Windows 8.1 apps, you can no longer use an iframe for non-secure http URIs. You will get the error message in the question which suggests that you can just add your URI to ApplicationContentUriRules, but it will only allow you to add https URIs to the rules.

So you will have to use the proprietary <x-ms-webview> tag instead of <iframe> if you want to serve non-secure content from your app. (e.g. <x-ms-webview src="http://www.google.com">)

see http://www.kraigbrockschmidt.com/2014/01/13/frame-to-webview-part-one/



回答2:

When migrating to Windows 8.1, you should use the x-ms-webview control in place of an iframe in most cases. It's generally as simple as replacing with in your markup. If you have postMessage communication with the iframe in Win8, however, you'll need to convert that code to use the webview's invokeScriptAsync (to call functions in the webview) and use window.external.notify to raise events back to the app.



回答3:

You need to open apppackage.manifest file and go to Content URIs tab, include the url you are trying to launch from iframe.