我有一个Xamarin.Forms应用程序,它通过Uno Platform投影到WASM 。单击或点击后,我需要打开一个Web链接。我用以下方法解决:
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.
}
Xamarin。Android&iOS和UWP(Windows)。但是,Xamarin.Essentials尚不能在WASM上运行。因此,我需要调用Javascript并运行以下代码:
function openPage(x) {
window.open(x);
}
我尝试将UNO.Foundation用于
WebAssemblyRuntime.InvokeJS("(function(){location.href=\"https://www.wikipedia.com/\";})();");
但是,它干扰了UWP UI类并破坏了我的项目。如何在不使用UNO.Foundation类的情况下从Xamarin.Forms页面C#后端调用Javascript?谢谢。
您可以使用混合Web视图,然后注入JavaScript代码以检测对此Web视图的每次单击https://docs.microsoft.com/zh-cn/xamarin/xamarin-forms/app-fundamentals/custom-renderer/hybridwebview
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句