1

I have a Xamarin.Forms app and it projected to WASM via Uno Platform . I need open a web link after click or tap. I solve it with:

 try // Uwp & iOS & Android
            {
                await Browser.OpenAsync(new Uri("http://localhost"), BrowserLaunchMode.SystemPreferred); // Open url in-app browser for iOS & Android- native in UWP
            }
            catch (NotImplementedInReferenceAssemblyException ex) //Wasm falls here because lack of Xamarin.Essentials.
            {
                await DisplayAlert("Hata", "Not supported on WASM", "Anladım"); // Show the info about exception.



            }

for Xamarin. Android & iOS and UWP(Windows). However, the Xamarin.Essentials cannot run on WASM yet. So I need to invoke the Javascript and run this code:

function openPage(x) {
    window.open(x);
}

I try to use UNO.Foundation for

WebAssemblyRuntime.InvokeJS("(function(){location.href=\"https://www.wikipedia.com/\";})();");

However, it interfere with the UWP UI classes and brokes my project. How can I invoke Javascript from Xamarin.Forms page C# backend without using UNO.Foundation class ? Thanks.

1 Answer 1

1

You can use hybrid webview then inject JavaScript code to detect every click on this web view https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/hybridwebview

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.