23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

When an iframe is in the web context, note that its page can contain ms-appx-web references to<br />

in-package resources, even if the page is loaded from a remote source (http[s]). Such pages, of course,<br />

would not work in a browser.<br />

The last two items in the table really mean that a Windows Store app cannot navigate from its<br />

top-level page (in the local context) directly to a web context page of any kind (local or remote) and<br />

remain within the app: the browser will be launched instead. That’s just life in the app host! Such<br />

content must be placed in an iframe.<br />

Similarly, navigating from a web context page to a local context page is not allowed by default, but<br />

you can enable this by calling the super-secret function MSApp.addPublicLocalApplicationUri from<br />

code in a local page (and it actually is well-documented) for each specific URI you need:<br />

//This must be called from the local context<br />

MSApp.addPublicLocalApplicationUri("ms-appx:///frame-local.html");<br />

The Direct Navigation example for this chapter gives a demonstration of this (as does Scenario 6 of<br />

the Integrating content and controls from web services sample). Do be careful when the URI contains<br />

query parameters, however. For example, you don’t want to allow a website to navigate to something<br />

like ms-appx:///delete.html?file=superimportant.doc!<br />

One other matter that arises here is the ability to grant a web context page access to specific<br />

functions like geolocation, writing to the clipboard, the app cache, and IndexedDB—things that web<br />

pages typically assume they can use. By default, the web context in a Store app has no access to such<br />

operating system capabilities. For example, create a new Blank project in Visual Studio with this one line<br />

of <strong>HTML</strong> in the body of default.html:<br />

<br />

Then set the Location capability in the manifest (something I forgot on my first experiment with<br />

this!), and run the app. You’ll see the Bing page you expect. 17 However, attempting to use geolocation<br />

from within that page—clicking the locator control to the left of “World,” for instance—will give you the<br />

kind of error shown in Figure 3-1.<br />

FIGURE 3-1 Use of brokered capabilities like geolocation from within a web context will generate an error.<br />

17 If the color scheme looks odd, it’s because the iframe is picking up styles from the default ui-dark.css of WinJS. Try<br />

changing that stylesheet to ui-light.css for something that looks more typical.<br />

88

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!