简体   繁体   English

调用调用后读取DOM对象

[英]Read DOM object after the invoke call

How can i read the value of the callback message from a javascript call. 我如何从JavaScript调用中读取回调消息的值。

Here is my code: 这是我的代码:

 private void OnDocumentLoaded(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
      CallbackHandler callback = new CallbackHandler(EndRequestNormally, EndRequestWithNoData);
      SendJavaScript(CreateRequestCompleteListenerScript());

        theBrowser.Document.InvokeScript("RequestCompleteListener", new object[] { callback });
        theBrowser.Document.InvokeScript("AjaxObjectHandle", new object[] { _parameters });
    }

 private void EndRequestNormally()
    {
        SetWebWidgetWindowSize();
    }

 private void SendJavaScript(string script)
    {
        theBrowser.Document.InvokeScript("eval", new object[] {script});
    }

 private string CreateRequestCompleteListenerScript()
    {
        StringBuilder script = new StringBuilder();
        script.AppendLine("var RequestCompleteListener = function(callback) {");
        script.AppendLine("    var internalCallback = {");
        script.AppendLine("        handleCallback:function(message, params){");
        script.AppendLine("            if (message == null){");
        script.AppendLine("                 callback.HandleNullMessage();");
        script.AppendLine("            } else {");
        script.AppendLine("                 callback.HandleRequestComplete();");
        script.AppendLine("            }");
        script.AppendLine("        }");
        script.AppendLine("    }");
        script.AppendLine("    UpdateAjaxObject.addListener('requestcomplete', internalCallback.handleCallback, internalCallback);");
        script.AppendLine("};");
        return script.ToString();
    }



    [System.Runtime.InteropServices.ComVisible(true)]
    public class CallbackHandler
    {
        public CallbackHandler(VoidHandler requestCompleteAction, VoidHandler nullMessageAction)
        {
            _requestCompleteAction = requestCompleteAction;
            _nullMessageAction = nullMessageAction;
        }

        private VoidHandler _requestCompleteAction;
        private VoidHandler _nullMessageAction;
        private bool _requestCompleted;

        [System.Runtime.InteropServices.DispId(0)]
        public void HandleRequestComplete()
        {
            if (!_requestCompleted)
                _requestCompleteAction();
            _requestCompleted = true;
        }

        [System.Runtime.InteropServices.DispId(1)]
        public void HandleNullMessage()
        {
            if (!_requestCompleted)
                _nullMessageAction();
        }
    }

The above code is just making the call. 上面的代码只是进行调用。

What i want is, to read the value in the message after the call. 我想要的是在通话后读取消息中的值。

The image below contains the values in the AJAX object 下图包含AJAX对象中的值

I want to get the count of the binshares under tradeschedule. 我想获取交易时间表下的binshare数量。 DOM的图片

Is there a way to that? 有办法吗?

Any help is appreciated. 任何帮助表示赞赏。

Thanks 谢谢

Do you mean you just want to get at it with JavaScript? 您是说只想使用JavaScript吗? <script>alert(AjaxObject.messages.tradeSchedule.binShares[0]);</script> You didn't expand the binShares array so I'm not sure what's under there. <script>alert(AjaxObject.messages.tradeSchedule.binShares[0]);</script>您没有扩展binShares数组,所以我不确定其中的内容。

I see you made changes, you want the length of binShares, do this... 我看到您进行了更改,您想要binShares的长度,执行此操作...

<script>alert(AjaxObject.messages.tradeSchedule.binShares.length);</script>

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

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