Steven
Steven

Reputation: 207

UWP/WinJS: show a html page in a pop-up window

I am working on a JavaScript based UWP app. Now I need to dynamically show a html page(with a url) in a pop-up window. I did some search, there is a ContentDialog I can probably use:

var object = new WinJS.UI.ContentDialog(element, options);

but I cannot find any JavaScript sample code for it. I couldn't figure out what should I pass as "element" and how I put the html in ContentDialog. Thanks in advance for any help.

Upvotes: 1

Views: 766

Answers (1)

Anthony Weber
Anthony Weber

Reputation: 372

The WinJS playground shows you how to use the ContentDialog: http://winjs.azurewebsites.net/#contentdialog

The element you pass is the Html element you want to initiate as the dialog.

<div id="myDialog">I am the going to be the dialog content.</div>

 

var element = document.getElementById('myDialog');
var options = {
         title: 'Main instruction',
         primaryCommandText: 'Ok',
         secondaryCommandText: 'Cancel'
    };
var dialog = new WinJS.UI.ContentDialog(element, options);

If you want to set the dialog content dynamically you can do so with

var webview = document.createElement('x-ms-webview');
webview.src = 'http://stackoverflow.com';
dialog.element.querySelector('.win-contentdialog-content').appendChild(webview);
dialog.show();

Upvotes: 2

Related Questions