简体   繁体   English

XLabs.Forms.Controls.HybridWebView 不显示 html/js 警报

[英]XLabs.Forms.Controls.HybridWebView does not show html/js Alert

I'm implementing the hybridWebView into our xamarin forms app.我正在将 hybridWebView 实现到我们的 xamarin 表单应用程序中。 The problem i've come across is that the hybridWebView doesn't show the alert messages from the website that is in the webView.我遇到的问题是 hybridWebView 没有显示来自 webView 中网站的警报消息。 I've just got a simple html page which has the following js function:我刚刚有一个简单的 html 页面,它具有以下 js 功能:

function testAlert() {
    alert('tester');
}

When I call this using CallJsFunction nothing occurs.当我使用 CallJsFunction 调用它时,没有任何反应。 I know it's firing because if i put something else in the function to say update the html on the page then it fires just fine.我知道它正在触发,因为如果我在函数中添加其他内容来更新页面上的 html,那么它就可以正常触发。

Is there any properties i need to set to show alerts in the view.是否需要设置任何属性以在视图中显示警报。 I know the built in Xamarin forms webview shows alerts just fine.我知道内置的 Xamarin 表单 webview 显示警报就好了。

I have created a sample on GitHub which basically does what you want in two ways when using HybridWebView for XLabs:在 GitHub 上创建了一个示例,当使用HybridWebView for XLabs 时,它基本上可以通过两种方式完成您想要的操作:

  1. Executing the CallJsFunction() method (bound to the Clicked event of a Button seen here )执行CallJsFunction()方法(绑定到此处看到的ButtonClicked事件)
  2. Utilising the InjectJavaScript() method (bound to the Clicked event of a Button seen here )使用InjectJavaScript()方法(绑定到此处看到的ButtonClicked事件)
  3. Overriding OnAppearing for the ContentPage , then calling LoadFromContent() with a simple .html page are both stored locally for iOS and Android覆盖ContentPage OnAppearing ,然后使用简单的.html页面调用LoadFromContent()都存储在本地用于iOSAndroid

As a note, I had to create a dependency called FilePath to be able to retrieve the path to the .html file for both Android and iOS as the file systems are different.请注意,我必须创建一个名为FilePath的依赖项,以便能够检索AndroidiOS.html文件的路径,因为文件系统不同。

This approach worked fine for Android, but not for iOS.这种方法适用于 Android,但不适用于 iOS。 I, much like you, didn't see any alert.我和你一样,没有看到任何警报。 For that reason, I have created an issue on the Github Issue Tracker for XLabs .出于这个原因,我在Github Issue Tracker for XLabs上创建了一个问题。 I know it's not much right now, but hopefully they'll get back with a solution.我知道现在不是很多,但希望他们能找到解决方案。 If not, it should be possible to simply change their Custom Renderer for the HybridWebView for iOS and thereby resolve the issue.如果没有,应该可以简单地为 iOS 的HybridWebView更改他们的自定义渲染器,从而解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM