procedure TForm1.Button3Click(Sender: TObject);
var
hr: HRESULT;
pDisp: IDispatch;
pDocument: IHTMLDocument2;
pBody: IHTMLElement;
pElement: IHTMLElement2;
BEGIN
pDisp := WebBrowser1.Document;
hr := pDisp.QueryInterface(IID_IHTMLDocument2, pDocument);
pBody := pDocument.body;
hr := pBody.QueryInterface(IID_IHTMLElement2, pElement);
edit2.Text :=inttostr(pelement.Get_scrollleft );
END;
//////////根据论坛搜索到的资料我写了以上的代码,但是 不管怎么移动滚动条,edit2.text中得到的结果始终是‘0’。
我错在哪里?请高手指点迷津!
谢谢!
var
hr: HRESULT;
pDisp: IDispatch;
pDocument: IHTMLDocument2;
pBody: IHTMLElement;
pElement: IHTMLElement2;
BEGIN
pDisp := WebBrowser1.Document;
hr := pDisp.QueryInterface(IID_IHTMLDocument2, pDocument);
pBody := pDocument.body;
hr := pBody.QueryInterface(IID_IHTMLElement2, pElement);
edit2.Text :=inttostr(pelement.Get_scrollleft );
END;
//////////根据论坛搜索到的资料我写了以上的代码,但是 不管怎么移动滚动条,edit2.text中得到的结果始终是‘0’。
我错在哪里?请高手指点迷津!
谢谢!
解决方案 »
- 在vista home basic上安装delphi 7,0的方法
- 上传文件问题 服务器端怎么接收???
- 更改数据库端口号问题
- 在delphi6下如何安装fastreport3.25
- 这几个涵数我不知道怎么翻译成delphi?
- 面试资讯课长,要准备回答哪些问题?
- 我用ADO+ORACLE开发的activeX网页,客户端总是提示我要安装ORACLE呢?必须安装吗?
- 请教大家一个有关IE类型的Toolbar问题(比较特殊的toolbar遮挡问题)
- delphi5与delphi6能否存
- 在IE4下为何无法往工具条上增加按钮,也不能往菜单里增加菜单项?我该怎么办?
- 如何解决在VISTA系统下继续运行BDE连接SQLSERVER的程序的问题!!!!谢谢
- 关于advstringgrid中combobox的ID或标志的问题!
var
vElement: IHTMLElement2;
begin
if not Assigned(WebBrowser1.Document) then Exit;
vElement := (WebBrowser1.Document as IHTMLDocument2).Body as IHTMLElement2;
Edit2.Text := IntToStr(vElement.scrollTop);
end;代码上就做了点简化而已。
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>ABC您的英语培训专家</title>
<style type="text/css">
<!--
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
body {
margin-top: 0px;
}
-->
</style>
<link href="css/text.css" rel="stylesheet" type="text/css">
<link href="css/Onlinestudy.css" rel="stylesheet" type="text/css">
</head><body>
<div align="center">
<br>
<br>
<br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#E6E6E6"><div align="right"><span class="font12_1"> ABC中国首页 </span></div></td>
</tr>
</table>
<table width="98%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="750" height="410" align="middle">
<param name="movie" value="abc-flash2.swf">
<param name="quality" value="high">
<embed src="abc-flash2.swf" width="750" height="410" align="middle" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>
</object>
</div></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#E6E6E6"><div align="left"><a href="aboutus/default.asp" target="_blank" class="font12_1"> 联系我们</a><span class="font12_1"> | <a href="zhaopinweb/zhaopinzhiwei.html" target="_blank" class="font12_1">ABC招聘</a></span></div></td>
</tr>
</table>
<table width="476" height="44" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="227" rowspan="2" bgcolor="#FFFFFF">
<div align="center" class="font12_1">
<div align="right"><a href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202003042800007" target="_blank"><img src="oak/new-index/images/biaoshi.gif" width="40" height="48" border="0"></a><a href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202003042800007"></a><br>
</div>
</div>
<div align="center"></div></td>
<td width="439" bgcolor="#FFFFFF"><div align="left"><span class="font12_1">版权所有:北京径成英教育文化发展有限公司<br>
办学许可证号:(京)教社证字G9212号 <a href="http://www.miibeian.gov.cn" class="font12_1">京ICP证030067号</a></span></div></td>
</tr>
<tr>
<td height="22" bgcolor="#FFFFFF"><div align="left"><span class="font12_1">Email:<a href="mailto:[email protected]" target="_blank" class="font12_1">[email protected]</a></span></div></td>
</tr>
</table>
</div>
</body>
</html>
网址:http://www.abc.com.cn/
我的测试网页:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<a href="file:///C|/Documents and Settings/Administrator/My Documents/a.html" target="_blank"><img src="file:///E|/图片/美女/2.jpg" width="1024" height="768" border="0" /></a>
</body>
</html>
<script type="text/javascript">
// 说明:用 Javascript 获取滚动条位置等信息
// 来源 :ThickBox 2.1
// 整理 :CodeBit.cn ( http://www.CodeBit.cn )
function getScroll()
{
var t, l, w, h;
if (document.documentElement && document.documentElement.scrollTop) {
t = document.documentElement.scrollTop;
l = document.documentElement.scrollLeft;
w = document.documentElement.scrollWidth;
h = document.documentElement.scrollHeight;
} else if (document.body) {
t = document.body.scrollTop;
l = document.body.scrollLeft;
w = document.body.scrollWidth;
h = document.body.scrollHeight;
}
return { t: t, l: l, w: w, h: h };
}
</script>翻译一下:
var
vElement: IHTMLElement2;
begin
if not Assigned(WebBrowser1.Document) then Exit;
vElement :=
(WebBrowser1.Document as IHTMLDocument3).documentElement as IHTMLElement2;
if not Assigned(vElement) then
vElement := (WebBrowser1.Document as IHTMLDocument2).Body as IHTMLElement2;
Edit2.Text := IntToStr(vElement.scrollTop);
end;163和楼主给的html测试均可获取。