Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

How to Invoke JavaScript from Xamarin.Forms app without using Uno.UI?

$
0
0

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.


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>