LaunchUriAsync | launchUriAsync methods

Launcher.LaunchUriAsync | launchUriAsync methods

[ Updated for UWP apps on Windows 10. For Windows 8.x articles, see the archive ]

Starts the default app associated with the URI scheme name for the specified URI.

Overload list

MethodDescription
LaunchUriAsync(Uri) Starts the default app associated with the URI scheme name for the specified URI.
LaunchUriAsync(Uri, LauncherOptions) Starts the default app associated with the URI scheme name or the one specified by the ContentType for the specified URI, using the specified options.
LaunchUriAsync(Uri, LauncherOptions, ValueSet) Starts the default app associated with the URI scheme name for the specified URI, using the specified options and input data.

Remarks

Unless you are calling this API from a Classic Windows application, this API must be called from within an ASTA thread (also known as a UI thread).

This API may also be called from Classic Windows applications.

Examples

Launch a URI

This example uses LaunchUriAsync(Uri) | launchUriAsync(Uri) to launch a URI.



// The URI to launch
var uriToLaunch = "http://www.bing.com";

// Create a Uri object from a URI string 
var uri = new Windows.Foundation.Uri(uriToLaunch);

// Launch the URI
Windows.System.Launcher.launchUriAsync(uri).then(   
   function (success) {
      if (success) {
        // URI launched
      } else {
        // URI launch failed
      }
   });

Launch with a warning dialog

Call launchUriAsync(Uri, LauncherOptions) to launch a URI with a warning. Use the treatAsUntrusted property to inidcate that the system should display a warning.

Note  

For Windows Store apps using JavaScript, call preventDefault in your event handler if the treatAsUntrusted property is set and you are using an a element to launch the URI.

 

function linkClickHandler(eventInfo) {
    var link = eventInfo.target;
    if (eventInfo.srcElement && (
        (eventInfo.type === "click") ||
        (eventInfo.type === "keydown" && (
        eventInfo.keyCode === WinJS.Utilities.Key.enter ||
        eventInfo.keyCode === WinJS.Utilities.Key.space)))) {
        eventInfo.preventDefault();
        if (link.href.indexOf("ms-appx") > -1) {
            WinJS.Navigation.navigate(link.href);
        }
        else if (link.href.indexOf("http") > -1) {
            // Create a Uri object from a URI string 
            var uri = new Windows.Foundation.Uri(link.href);
            var options = new Windows.System.LauncherOptions();
            // Launch the URI with a warning prompt
            options.treatAsUntrusted = true;
            // Launch the URI
            Windows.System.Launcher.launchUriAsync(uri, options).then(
                function (success) {
                    if (success) {
                        // URI launched
                    } else {
                        // URI launch failed
                    }
                });
        }
    }
}

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8

Namespace

Windows.System
Windows::System [C++]

Metadata

Windows.winmd

See also

Samples
Association launching sample
Guidelines
Guidelines for file types and URIs
Tasks
How to launch the default app for a URI (JavaScript)
Launch the default app for a URI
Reference
Launcher
LauncherOptions

 

 

Show:
© 2016 Microsoft