user5773230
user5773230

Reputation:

UWP - Stopping / Disallowing WebView from Opening New Browser Window - C++

I am working on a UWP app and the app uses WebView to open a couple of pages. But the problem is that every time user clicks on an external link, the app opens Microsoft Edge to show that link. Is there any way to stop the app launching Edge every time user interacts with the WebView? In fact I don't want those links to open at all.
I tried to google for it but I really didn't know what to search for. So I decided to ask for help.
I can also provide the code if that's relevant here. Thanks

Upvotes: 0

Views: 857

Answers (1)

user5773230
user5773230

Reputation:

I found an article onWebView.NewWindowRequestedat UWP WebView and it solved my problem. The piece of code that I used in my program is here:

void MultiPageWeb::CouchTuner::OnNewWindowRequested
 (Windows::UI::Xaml::Controls::WebView^ sender,
  Windows::UI::Xaml::Controls::WebViewNewWindowRequestedEventArgs^ e)
{
     auto myWebView = ref new WebView();
     myWebView->Navigate(e->Uri);
     myGrid->Children->First();
     e->Handled = true;
}

myGrid is the name of the Grid available in XAML page of the application and First() only keeps the master webpage and doesn't load the other pages which can be launched through the clicks. Furthermore, the XAML page needs to include the following code:

<WebView x:Name="myWebView" NewWindowRequested="OnNewWindowRequested"/>

Hopefully, it will help someone along the way.

Upvotes: 1

Related Questions