Kyle Baran
Kyle Baran

Reputation: 37

How do I open a link in the system browser from a UWP app using javascript?

I've developed a web app. I'm using Cordova to create app wrappers for Android/iOS/OSX/Windows, and when I test the Windows app, I'm encountering an issue.

The app interacts with a lot of links outside my app's domain, both accessing third-party user content and using OAuth to do login for users via third-party services. The OAuth redirects are generated from my app's backend server and then the user is manually redirected to them via javascript.

let response = await this.$apollo.mutate({
  mutation: initializeConnection,
  variables: variables
});

window.location = response.data.initializeConnection.redirectUrl;

In Android/iOS/OSX, this opens the OAuth redirect in the system browser, which is what I want. The Windows app, though, does not. I've got my app's URLs set as <allow-navigation>'s in the Cordova config.xml file, which inserts them into the appmanifest when it's built for Windows (they show up as Content URIs). When the above redirect occurs in Windows, there's an error that reads "The app can't use script to load the <url> url because the url launches another app."

I don't want to open another app, I just want to open them in the system browser. As a point of comparison, user content that I manifest as <a href="<whatever>" target="_blank"> will open in the system browser just fine. I tried using window.open() to open the redirects instead of window.location, and while that does work if I add "https://*" to the Content URIs, that will open the redirect in another app window, not the system browser.

What do I need to do to get these redirects opening in the system browser?

Upvotes: 0

Views: 435

Answers (1)

danchik
danchik

Reputation: 181

in UWP can do this to open default browser with the url

Windows.System.Launcher.launchUriAsync(  
    new Windows.Foundation.Uri(url))
    .then(function (success) {
        if (success) {
            console.log('opened ' + url);
        } else {
            console.log('failed opening ' + url);
        }
    });

Upvotes: 1

Related Questions