简体   繁体   English

如何解决window.close()在Android Webview中不起作用C#

[英]how to solve window.close() not work in Android webview c#

i just new using this visual studio c# android... 我只是新使用此Visual Studio C#Android ...

have system develop in vb.net... working fine in website... problem when wanted using mobile app... used this vs c# xamarin android.... 在vb.net中有系统开发...在网站上可以正常工作...想要使用移动应用程序时出现问题...使用了此vs c#xamarin android ....

protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle);

    SetContentView(Resource.Layout.Main);

    WebView localWebView = FindViewById<WebView>(Resource.Id.LocalWebView);
    localWebView.SetWebViewClient(new WebViewClient()); // stops request going to Web Browser
    localWebView.Settings.JavaScriptEnabled = true;
    localWebView.Settings.JavaScriptCanOpenWindowsAutomatically = true;
    localWebView.SetWebChromeClient(new WebChromeClient());
    localWebView.LoadUrl("http://www.facebook.com");

}

success run on this webview.... but have form have window.open....problem is how to window.close after used javascript to opened it.. means going back to my previous window.. and pass some information.... like: window.opener.document.getElementById(StrCtrlName2).value = MemberCode; 成功在此webview上运行....但是表格具有window.open ....问题是在使用JavaScript将其打开后如何window.close ..意味着返回到我以前的窗口..并传递了一些信息.. .. like:window.opener.document.getElementById(StrCtrlName2).value = MemberCode;

find and want to try this code... but look different for c#... how to convert it in visual studio c# because have error??... help me.. where to pun also i'm not sure... just learn c# 查找并想尝试此代码...但是对于C#而言却看起来不同...如何在Visual Studio C#中将其转换,因为有错误?...帮助我..在哪里打双关语我也不确定...只是学习C#

WebChromeClient webClient = new WebChromeClient(){

    public void onCloseWindow(Window w){
        super.onCloseWindow(w);
        Log.d(TAG, "Window close");
    }
};

thanks... 谢谢...

Welcome @haris! 欢迎@haris!

The code you found is java. 您找到的代码是java。 It's different from c# but also have a lot similarities. 它与c#不同,但也有很多相似之处。

If you want this particular java snippet in c# you would have do write something like this: 如果您想在C#中使用这个特定的Java代码段,则可以编写如下代码:

    using Android.Webkit;
    public class CustomWebChromeClient : WebChromeClient { 

        public override void OnCloseWindow(Android.Webkit.WebView window)
        {
            base.OnCloseWindow(window);
            //Your favorite logging library call.
        }

    }

A quick explanation (in case you are interested). 快速说明(如果您有兴趣)。

In java snippet a ref to anonymous class which extends WebChromeClient is created and then we extend base onCloseWindow method by adding addition logging. 在Java代码段中,创建了对扩展WebChromeClient的匿名类的引用,然后我们通过添加附加日志扩展onCloseWindow方法。

In c# the same can not be done so what I did, just created a named class CustomWebChromeClient which extends WebChromeClient and overrides OnCloseWindow 在c#中,无法做到这一点,我只是创建了一个命名类CustomWebChromeClient ,该类扩展了WebChromeClient并覆盖了OnCloseWindow

For more info refer to official Xamarin docs . 有关更多信息,请参阅Xamarin官方文档

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

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