C# 控制IE,如何获取Iframe里面的document对象??

pasty1314 2010-07-09 11:19:18
写了个方法获取到了打开某个指定连接的IE窗口的IHTMLDocument2 对象,页面里有个iframe,我现在只能拿到外部的doument对象,要怎么才能拿到iframte里的document啊,我要操作里面的dom..急急急.

public static IHTMLDocument2 GetIHTMLDocument2ByUrl(string url)
{
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
string filename = ie.FullName.ToLower();
Console.WriteLine(filename);
if (filename.IndexOf(@"internet explorer\iexplore") > 0 && ie.LocationURL == url)
{
return ie.Document as IHTMLDocument2;

}

}
return null;
}



我试过很多方法
IHTMLDocument2.frames
IHTMLDocument2.parentWindow.frames
等等都不行..
...全文
461 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
自有编程者 2010-08-25
  • 打赏
  • 举报
回复
获取iframe document对象:var ifr = iframeName.contentWindow.document
ifr.body.appendChild(divobj)
pasty1314 2010-07-14
  • 打赏
  • 举报
回复
js动态插入iframe的.
pasty1314 2010-07-10
  • 打赏
  • 举报
回复


我打开了指定连接的IE窗口,代码第一行也拿到了那个IE窗口的document,但再拿ifrmate的时候总是报错,不知道为什么.
jshi123 2010-07-10
  • 打赏
  • 举报
回复
jshi123 2010-07-10
  • 打赏
  • 举报
回复
var doc = ie.Document as IHTMLDocument2;
object i = 0;
var iframe = doc.frames.item(ref i) as IHTMLWindow2;
IHTMLDocument2 innerDoc = iframe.document; // innerDoc即为iframe里的document

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧