【问题标题】:How do I append child node in an Internet Explorer BHO extension?如何在 Internet Explorer BHO 扩展中附加子节点?
【发布时间】:2012-07-12 17:46:27
【问题描述】:

我正在移植一个 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);
    }

【问题讨论】:

    标签: c# internet-explorer bho browser-extension


    【解决方案1】:

    您需要使 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);
    }
    

    【讨论】:

    • @redaid:如何以及在何处创建 doSomething()?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-16
    • 2015-01-27
    • 1970-01-01
    • 1970-01-01
    • 2020-09-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多