标签: ihtmldocument2

MSHTML教程

我想学习一些关于MSHTML的基础知识,比如如何使用IHtmlDocument和IHtmlDocument2接口.我搜索了很长一段时间,但找不到初学者的教程.有人可以推荐一些东西吗?

编辑:我更喜欢使用C#.

mshtml ihtmldocument ihtmldocument2

5
推荐指数
1
解决办法
7867
查看次数

在C#Webbrowser控件WPF中从Javascript获取返回值

我在C#中使用JavaScript注入WebBrowser控件,(System.Windows.Controls.WebBrowser) 这样,<C#>

IHTMLDocument2 webdoc = (IHTMLDocument2)webBrowser1.Document;
string var = File.ReadAllText("C:/.../Resources/script.txt");
object retVal = webdoc.parentWindow.execScript(var, "Jscript");
Run Code Online (Sandbox Code Playgroud)

和JavaScript文件script.txt是,

var headID = document.getElementsByTagName('head')[0];
var newScript = document.createElement('script');
newScript.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js'
headID.appendChild(newScript)

$('body').bind('click',function(e){
    var domsArray = [];
    for (var i = 0; i < 15; i++){
        for (var j = 0; j < 15; j++){
            if (document.elementFromPoint(e.clientX+i, e.clientY+j) && (jQuery.inArray(document.elementFromPoint(e.clientX+i, e.clientY+j), domsArray) < 0)){
            domsArray.push(document.elementFromPoint(e.clientX+i, e.clientY+j));
            }if (document.elementFromPoint(e.clientX-i, e.clientY+j) && (jQuery.inArray(document.elementFromPoint(e.clientX-i, e.clientY+j), domsArray) < 0)){
            domsArray.push(document.elementFromPoint(e.clientX-i, e.clientY+j));
            }if (document.elementFromPoint(e.clientX+i, e.clientY-j) && (jQuery.inArray(document.elementFromPoint(e.clientX+i, …
Run Code Online (Sandbox Code Playgroud)

javascript c# wpf webbrowser-control ihtmldocument2

5
推荐指数
1
解决办法
1277
查看次数

如何获得由几个IHTMLElements组成的IHTMLElementCollection obj?

伙计们:我在object-pascal编程中遇到了"如何获得由几个IHTMLElements组成的IHTMLElementCollection obj"的问题,我的代码如下:

function TExDomUtils.GetElementsByClassName(vDoc:IHTMLDocument3; strClassName:string):IHTMLElementCollection;
var
  vElementsAll : IHTMLElementCollection;
  vElementsRet : IHTMLElementCollection;
  vElement : IHTMLElement;
  docTmp : IHTMLDocument2;
  I ,J: Integer;
begin
  J := 0;
  vElementsAll := vDoc.getElementsByTagName('*');
  for I:=0 to vElementsAll.length - 1 do
  begin
    vElement := vElementsAll.item(I,0) as IHTMLElement;
    if vElement.getAttribute('class',0) = strClassName then
    begin
      // how to get an IHTMLElementCollection obj which composed of several IHTMLElements?
      J := J + 1;
    end;

  end;

  Result := vElementsRet;
end;
Run Code Online (Sandbox Code Playgroud)

delphi pascal mshtml ihtmldocument2

5
推荐指数
1
解决办法
5504
查看次数

无法使用IHTMLDocument2

$wc = New-Object System.Net.WebClient
$DownloadString = $wc.DownloadString("http://www.example.com")
$HTML = New-Object -ComObject "HTMLFile"
$HTML.IHTMLDocument2_write($DownloadString)
Run Code Online (Sandbox Code Playgroud)

运行服务器脚本

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      14409  1005
Run Code Online (Sandbox Code Playgroud)

开发PC

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      15063  502
Run Code Online (Sandbox Code Playgroud)

我的Windows 10开发PC在上面的代码中运行良好.我想在我的Server 2008 R2 x64机器上运行它.我将其升级到PowerShell v5.我得到以下内容:

方法调用失败,因为[System .__ ComObject]不包含名为"IHTMLDocument2_write"的方法.

后来......

Unable to find type [mshtml.HTMLDocumentClass].
Run Code Online (Sandbox Code Playgroud)

powershell internet-explorer ihtmldocument2 windows-server powershell-5.0

4
推荐指数
1
解决办法
2215
查看次数

迭代IHTMLElementCollection

有没有办法迭代IHTMLElementCollection?

var
  e : IHTMLLinkElement;
elementCollection:IHTMLElementCollection;
begin
    for e in elementCollection do
      showmessage(e.caption);
end;
Run Code Online (Sandbox Code Playgroud)

我知道有一个名为_newEnum的属性,但是delphi中不支持它,因为我能理解.

update:apperently链接是IHTMLElement而不是IHTMLLinkElement

delphi loops delphi-2009 ihtmldocument2

1
推荐指数
1
解决办法
3785
查看次数

IHTMLDocument2的可用内存

我正在使用IHTMLDocument2:

var
  doc: OleVariant;

doc:= coHTMLDocument.Create as IHTMLDocument2;
doc:= CreateComObject(Class_HTMLDOcument) as IHTMLDocument2;
doc.write(html);
doc.close;
(...)
Run Code Online (Sandbox Code Playgroud)

我应该如何妥善处理"doc"?

delphi ihtmldocument2

1
推荐指数
1
解决办法
436
查看次数

IHTMLDocument2无处不在

在winform应用程序中,我有WebBrowser控制权和a PictureBox.我正在加载一个Image(从webbrowser控件之后DocumentComplete)到pictureBox1,代码如下

IHTMLDocument2 doc = (IHTMLDocument2)webBrowser1.Document.DomDocument;
IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();

foreach (IHTMLImgElement img in doc.images)
    {

         imgRange.add((IHTMLControlElement)img);

         imgRange.execCommand("Copy", false, null);

         pictureBox1.Bitmap = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);

     }
Run Code Online (Sandbox Code Playgroud)

图像显示在我的电脑上的picturebox1中,但不是我朋友的.在另一个Windows XP上安装VS2008后它运行良好.所以我想IHTMLDocument2需要Windows更新才能正常工作.

哪个更新?或者这个代码的任何其他替代方案,我不必从互联网上重新下载图像?

c# ihtmldocument2

0
推荐指数
1
解决办法
9132
查看次数