繁体   English   中英

WebBrowser控件c#winform中的beforeunload事件的问题

[英]problem with beforeunload event in WebBrowser control c# winform

我已经编写了逻辑,甚至可以在beforeunload从Web应用程序注销,如下所示:

window.addEventListener("beforeunload", function (event) {  
   //Logout logic
   //Calling logout api with values from session
   //clearing the session on success 
});

它在所有Web浏览器(IE,Mozilla,Chrome)中都可以正常工作,但是在winform应用程序中无法通过WebBrowser控件运行。

背后的原因可能是什么?

PS:javascript没什么问题,当我通过如下调用它来调用相同的脚本时,它可以正常工作:

   HtmlElement head = webBrowser4.Document.GetElementsByTagName("head")[0];
   HtmlElement scriptEl = webBrowser4.Document.CreateElement("script");
   IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement;
   element.text = @"function Logout() {
   $.ajax({
         url: '/api/Logout',
         type: ""GET"",
         contentType: ""application/json;charset=utf-8"",
         success: function(returnVal) {
                    },
         complete: function() {
                     sessionStorage.clear();
                    },
         error: function(returnVal) {
                        }
                    });
                 }";
     head.AppendChild(scriptEl);
     webBrowser4.Document.InvokeScript("Logout");

什么是问题beforeunload事件WebBrowser控制winform

您在没有收听者的情况下尝试了吗?

window.onbeforeunload = function(event)

暂无
暂无

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

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