1

我正在移植一个 firefox 扩展程序,只是尝试将一个按钮附加到网页上的一个节点。但是页面上什么也没有发生。我相信它必须与 HTMLDOMNode 和 HTMLElement 之间的转换有关。使用 IE dev add on 在控制台内我什至没有收到任何错误。

我的代码:

public void OnDocumentComplete(object pDisp, ref object URL)
    {
        HTMLDocument document = (HTMLDocument)webBrowser.Document;
        var fblike = document.getElementById("LikePluginPagelet");

        var button = document.createElement("input");
        button.setAttribute("value", "myButton");
        button.setAttribute("onClick", "doSomething()");
        ((IHTMLDOMNode)fblike).appendChild((IHTMLDOMNode)button);
    }
4

1 回答 1

2

您需要使 fblike 动态化。

public void OnDocumentComplete(object pDisp, ref object URL)
{
    HTMLDocument document = (HTMLDocument)webBrowser.Document;
    var fblike = document.getElementById("LikePluginPagelet");

    var button = document.createElement("input");
    button.setAttribute("value", "myButton");
    button.setAttribute("onClick", "doSomething()");

    dynamic fbLike = fblike
    fbLike.appendChild((IHTMLDOMNode)button);
}
于 2012-07-12T09:46:27.223 回答