.Net Maui Webview URL retriever

Atilla Yadik 0 Reputation points
2023-04-05T01:57:15.3266667+00:00

Is there a way where I can listen to the changes in the webview or even the external browser's URL address changes from a .Net MAUI app? I want to get the URL address that the user is on with their permission of course. This will give them the functionality I am providing to the user, which that's why they have downloaded my app for that usuage. Can anybody help me with this? Thanks in advance....

Developer technologies .NET .NET MAUI
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2023-04-05T07:16:40.75+00:00

    Hello,

    Is there a way where I can listen to the changes in the webview or even the external browser's URL address changes from a .Net MAUI app?

    In MAUI you could use the API to listen for URL changes in the WebView, while for external browsers, you are not authorized to listen.

    You could refer to the following official documentation with a simple example:

    <WebView WidthRequest="500" HeightRequest="1000" Source="https://www.bing.com" Navigating="WebView_Navigating"/>
    
    private void WebView_Navigating(object sender, WebNavigatingEventArgs e)
    {
        if (e.Url.Contains("bing"))
        {
            Console.WriteLine("Bing is Navigating");
        }
    }
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.