How to get actual JavaScript value in onclick from webbrowser control?

前端 未结 6 1017
日久生厌
日久生厌 2020-12-29 09:26

I\'m looking for a way to get the JavaScript code defined inside of onclick. I\'m using .NET 2.0 C# Visual Studio 2005.

Example:

<         


        
6条回答
  •  再見小時候
    2020-12-29 09:44

    As per Sheng Jiang's response, here is some working sample:

    IHTMLElement element = YourCodeToGetElement();
    string onclick = string.Empty;
    
    IHTMLDOMNode domNode = element as IHTMLDOMNode;
    IHTMLAttributeCollection attrs = domNode.attributes;
    
    foreach (IHTMLDOMAttribute attr in attrs)
    {
        if (attr.nodeName.Equals("onclick"))
        {
            string attrValue = attr.nodeValue as string;
            if (!string.IsNullOrEmpty(attrValue))
            {
                onclick = attr.nodeValue;
                break;
            }
        }
    }
    

提交回复
热议问题