where is IHTMLScriptElement?

后端 未结 4 710
星月不相逢
星月不相逢 2020-12-31 01:28

I just started using Visual Studio 2010 C# IDE today.

I\'m trying to inject javascript to WebBrowser component and followed the answer from stackoverflow:

Ho

相关标签:
4条回答
  • 2020-12-31 01:48

    Project + Add Reference, select Microsoft.mshtml. If it doesn't appear in the list (it is a PIA) then use the Browse tab and select c:\windows\system32\mshtml.tlb

    Add a using directive at the top of the source code file:

    using mshtml;
    

    Beware that you have a deployment detail. If the PIA isn't installed on the target machine, which is not unlikely, then the best thing to do is to set the Copy Local property of the assembly reference to True. That creates the Microsoft.mshtml.dll file in the build folder. Copy it, along with your EXE onto the target machine. There are a few cases where a PIA is required, not this one.


    Update to this old post, .NET 4+ and VS2010+ now support the "Embed Interop Types" reference assembly property. Also known as the "No PIA" feature. This obsoletes the need for PIAs and is the superior way to deal with interop assemblies. It is set to True automatically, unless your project got started on an old version of VS.

    It has no down-sides, you no longer have to deploy the interop assembly and the interop types you use are now embedded in your executable file. Just the ones you use. A small change might be required in your code, if you now create the COM object with new XxxxClass() then you need to remove the "Class" part of the name.

    0 讨论(0)
  • 2020-12-31 01:50

    IHTMLScriptElement is defined in the Mshtml. You need to add a reference to the the Microsoft HTML Object Library and then add a "using mshtml" for VS to resolve IHTMLScriptElement.

    0 讨论(0)
  • 2020-12-31 02:08

    It is in Mshtml.dll.

    The System.Windows.Forms.HtmlElement's DomElement property is of type object, but actually a COM IUnknown pointer for the element, which you can cast to one of the HTML element interfaces, such as mshtml.IHTMLScriptElement.

    0 讨论(0)
  • 2020-12-31 02:09

    I'd recommend this answer for a managed-only solution for injecting javascript that doesn't require deploying a PIA like mshtml does.

    0 讨论(0)
提交回复
热议问题