HTML WebView control sample

This sample demonstrates how to use WebView.

 
 
 
 
 
3.7 Star
(3)
5,228 times
Add to favorites
11/26/2013
E-mail Twitter del.icio.us Digg Facebook
//// Copyright (c) Microsoft Corporation. All rights reserved

(function () {
    "use strict";

    var sampleTitle = "HTML WebView control sample";

    var scenarios = [
        { url: "/html/1_NavToUrl.html", title: "Navigate to a URL" },
        { url: "/html/2_NavToString.html", title: "Navigate to a string" },
        { url: "/html/3_NavToState.html", title: "Navigate to app state" },
        { url: "/html/4_NavToStream.html", title: "Navigate to a stream" },
        { url: "/html/5_InvokeScript.html", title: "Interact with script" },
        { url: "/html/6_ScriptNotify.html", title: "Use ScriptNotify" },
        { url: "/html/7_SupportShare.html", title: "Share with other apps" }
    ];

    function activated(eventObject) {
        if (eventObject.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
            // Use setPromise to indicate to the system that the splash screen must not be torn down
            // until after processAll and navigate complete asynchronously.
            eventObject.setPromise(WinJS.UI.processAll().then(function () {
                // Navigate to either the first scenario or to the last running scenario
                // before suspension or termination.
                var url = WinJS.Application.sessionState.lastUrl || scenarios[0].url;
                return WinJS.Navigation.navigate(url);
            }));
        }
    }

    WinJS.Navigation.addEventListener("navigated", function (eventObject) {
        var url = eventObject.detail.location;
        var host = document.getElementById("contentHost");
        // Call unload method on current scenario, if there is one
        host.winControl && host.winControl.unload && host.winControl.unload();
        WinJS.Utilities.empty(host);
        eventObject.detail.setPromise(WinJS.UI.Pages.render(url, host, eventObject.detail.state).then(function () {
            WinJS.Application.sessionState.lastUrl = url;
        }));
    });

    WinJS.Namespace.define("SdkSample", {
        sampleTitle: sampleTitle,
        scenarios: scenarios
    });

    WinJS.Application.addEventListener("activated", activated, false);
    WinJS.Application.start();

})();