在用C#往网页中添加元素时发现,有些情况下,工作正常,有些情况下不正常,网上查了好些资料,但是没有找到问题如何解。
在线等待。。。
问题,给一个div设定一个固定的高度,大多数情况下其工作正常,对于部分网页,有问题。
// top 就是个普通的div
IHTMLElement2 top = doc2.createElement("div") as IHTMLElement2;
top.style.visibility = "visible";
top.style.left = rect.X + "px";
top.style.top = ly + "px";
top.style.width = rect.Width + "px";
top.style.height = "5px"; // 关键是这里有时候不起作用
对于以上的输出结果,在大多数网页下,正确的情况下:
show div, cb.style visibility = visible, left = 286px, top = 185px, width = 403px, height = 5px, border color =
clientTop = 0,clientHeight = 5, currentSytle.Top=185px,currentStyle.bottom = auto,currentSytle.height=5px
在有些网页下,错误的输出结果如下:
show div, cb.style visibility = visible, left = 53px, top = 91px, width = 98px, height = 5px, border color =
clientTop = 0,clientHeight = 18, currentSytle.Top=91px,currentStyle.bottom = auto,currentSytle.height=5px
这个问题好像和<!DOCTYPE html ....>头有些关系,对于两个出错的情况,也就是clientHeight!=style.Height的情况,都是因为该网页中没有定义DOCTYPE。
问题:如何针对这种没有定义DOCTYPE的网页,设置指定的ClientHeight大小?谢谢
补充:比如这个网站就有问题http://211.98.70.84:8080/?HOST=xn--vnxs5qt6s&R=/&