admin管理员组

文章数量:1336289

I want to include a web hosted piece of javascript to act as a widget in my metro application. The goal would be to be able to maintain the state of the widget outside of the metro app so that a change to the widget code wouldn't require a repackaging and publishing to the app store.

e.g. (in my html file in the metro app)

<script type="text/javascript" src="/widget.js">

I want to include a web hosted piece of javascript to act as a widget in my metro application. The goal would be to be able to maintain the state of the widget outside of the metro app so that a change to the widget code wouldn't require a repackaging and publishing to the app store.

e.g. (in my html file in the metro app)

<script type="text/javascript" src="https://link.to.website/widget.js">
Share asked Mar 4, 2012 at 5:02 AbadabaAbadaba 1,4667 gold badges20 silver badges30 bronze badges 1
  • 2 If you do this, make sure it works without internet access too, or it will probably get rejected from the store. – parkovski Commented Mar 4, 2012 at 20:08
Add a ment  | 

2 Answers 2

Reset to default 9

It's important to understand the differences between the local and web context. Particular restrictions are documented here: http://msdn.microsoft./en-us/library/windows/apps/hh465373.aspx -- what is worth noting is that you can only include external script files from pages running in the web context.

Also, your app always has to have a top level page that is in your package. This page must be in the local context and loaded via the ms-appx scheme. This outer page may choose to iframe pages loaded in the web context (via ms-appx-web for in-package files or via http/https for pages hosted on the web.)

What you should keep in mind is that even though you can load external script into a web context page, that script cannot access the Windows Runtime APIs. If you want your external script to be able to call WinRT, you can create a munication channel using the HTML5 Web Messaging APIs.

If the metro apps lets you connect to the net (if the app is not limited to local-only or similar) that should be possible.

Also:

<script src="https://link.to.website/widget.js"></script>

not

<script type="text/javascript" src="https://link.to.website/widget.js">

Since JavaScript is the standard type for script, you do not have to declare that nowadays.

本文标签: windows 8Can web hosted javascript files be included in metro appsStack Overflow