delphi如何模拟点击网页按钮
本帖最后由 iaistudy 于 2014-7-19 10:26 编辑问题描述:单位的网上学习任务,要统计学习时间的,每隔10分钟点击下小窗口中的“更新学习时间按钮”,(此时小窗口最小化)。然后再点击网页消息框中的确定,最后再点击最大化更新学习时间那个小窗口。
初步计划在delphi中WebBrowser控件实现,浏览器弄好了,接下来点击“更新学习时间按钮” 按钮这一步实现不了。希望大家指点指点。
<html xmlns="http://www.w3.org/1999/xhtml">
<head >
<title>2014全员远程培训</title>
<script type="text/javascript" language="javascript">
var StrPath = location.href
if (StrPath.substring(0,4).toUpperCase()=="HTTP"){
document.domain='leekyoo.cn';
}
</script>
<script type="text/javascript" src="http://static.hainan.leekyoo.cn/fxl/js/floatWin.js"></script>
<script type="text/javascript" src="http://static.hainan.leekyoo.cn/fxl/js/StudyfrmNew.js"></script>
<script type="text/javascript" src="http://static.hainan.leekyoo.cn/fxl/js/pingbi.js"></script>
</head>
<body>
<div id="bg" style="z-index:1;position:absolute;left:0px;top:0px;width:100%;height:100%;background-color:#FFFFFF;filter:Alpha(opacity=80);visibility:hidden;">
<input type="hidden" id="isView" value="0"/></div>
<div id="divDrag" style="z-index:100;position:absolute; left:0px;top:0px;width:100%;height:100%;background-color:#FFFFFF; filter:Alpha(opacity=1);visibility:hidden;"> </div>
<iframe id="courseFrame" frameborder="0" scrolling="yes" src="http://course.leekyoo.cn/zxts001a/index.htm" width="100%" height="100%" style="z-index:1;"></iframe>
<div style="z-index:999;position:absolute;top:0;left:0;width:600px;height:20px;border:4px solid #336699;" id="msgtip" >
<div style="background-color:slategray;width:100%;height:20px;color:white;" title="按住鼠标左键拖动窗口"id="msgTitle">
<span style="width:80px;padding-left:3px;font-size:12px">更新学习时间</span>
<span id="btn" style="width:12px;border-width:0px;color:white;font-family:webdings;cursor:hand;" title="最小化"><img src="zuixiao.jpg" alt="" style="vertical-align: bottom; border:0px;"/></span>
</div>
<div id="msg" style="height:115px;width:100%;">
<iframe id="timeFrame" frameborder="0" scrolling="No" width="100%" height="115px" src="RecordTimeNew.aspx?bookid=86&StudyPlanBookID=53"></iframe>
</div>
</div>
</body>
</html>
下面是js代码:
var hover='orange',normal='slategray',normalbordercolor='#336699',strTop='',strLeft='';
window.onload =window.onscroll = scrollMsgTip;
var moveable=false;
var x0=0,y0=0,x1=0,y1=0;
//开始拖动;
function startDrag(obj)
{
if(event.button==1)
{
$("divDrag").style.visibility = "visible";
//锁定标题栏;
obj.setCapture();
//定义对象;
var win =$("msgtip");
//记录鼠标和层位置;
x0 = event.clientX;
y0 = event.clientY;
x1 = parseInt(win.style.left);
y1 = parseInt(win.style.top);
//记录颜色;
//normal = obj.style.backgroundColor;
//改变风格;
obj.style.backgroundColor = hover;
win.style.borderColor = hover;
//win.style.left = x1 ;
//win.style.top= y1 ;
moveable = true;
event.srcElement.setCapture();
}
}
//拖动;
function drag(obj)
{
if(moveable)
{
//小窗口宽度 高度
var winwidth=600,winheight=141;
var msg = $("msg");
var flg = msg.style.display=="none";
if(flg)
{
winwidth=300,winheight=25;
}
obj.setCapture();
var win = $("msgtip");
var bg = $("bg");
var x=x1 + event.clientX - x0;
var y=y1 + event.clientY - y0;
var l=document.body.scrollWidth;
var h=document.body.scrollHeight;
if(x<0){x=0;}
if(x+winwidth>l){x=l-winwidth;} //小窗口宽度为600
if(y<0){y=0;}
if(y+winheight>h){y=h-winheight;}
win.style.left =x;// x1 + event.clientX - x0;
win.style.top=y;// y1 + event.clientY - y0;
}
}
//停止拖动;
function stopDrag(obj)
{
if(moveable)
{
$("divDrag").style.visibility = "hidden";
var win = $("msgtip");
var msg = $("msg");
win.style.borderColor = normalbordercolor;
obj.style.backgroundColor = normal;
msg.style.color = normal;
obj.releaseCapture();
moveable = false;
event.srcElement.releaseCapture();
}
}
function min(obj)
{
var win = $("msgtip");
var tit = $("msgTitle");
var msg = $("msg");
var flg = msg.style.display=="none";
if(flg)
{
win.style.height= parseInt(msg.style.height) + parseInt(tit.style.height);
win.style.width = "600px";
msg.style.display = "block";
obj.innerHTML = "<img src=\"zuixiao.jpg\" style=\"vertical-align: bottom; border:0px;\"/>";//"0";
$("btn").title = "最小化";
if(strLeft!="" && strTop!="")
{
win.style.left = strLeft;
win.style.top= strTop;
}
else
{
scrollTip();
}
}
else
{
closeDiv();
}
}
function closeDiv()
{
var strisview=$("isView").value;
if(strisview=="1")
{
timeFrame.window.document.getElementById("glowtext").innerHTML="请更新学习时间!";
//timeFrame.window.startglowing();
return;
}
var win = $("msgtip");
var tit = $("msgTitle");
var msg = $("msg");
win.style.height= parseInt(tit.style.height);
win.style.width = "300px";
$("btn").innerHTML = "<img src=\"zuida.jpg\" style=\"vertical-align: bottom; border:0px;\"/>";//"2";
$("btn").title = "最大化";
msg.style.display = "none";
$("bg").style.visibility = "hidden";
strLeft=win.style.left;
strTop=win.style.top;
scroll();
}
var tScaler;//计时器
//随机展开DIV
function Time()
{
var win = $("msgtip");
var tit = $("msgTitle");
var msg = $("msg");
//var num = Math.round(Math.random()*10) + 10;//Math.floor(Math.random()*0) + 1 //产生一个 10-20之间的随机数
//tScaler = setTimeout("Time()",num * 60 * 1000);//根据随机数分钟数显示 IFrame ,在 IFrame 中提交时间
if(!msg) return;
win.style.height= parseInt(msg.style.height) + parseInt(tit.style.height);
win.style.width = "600px";
msg.style.display = "block";
$("btn").innerHTML = "<img src=\"zuixiao.jpg\" style=\"vertical-align: bottom; border:0px;\"/>";//"0";
$("bg").style.visibility = "visible";
scrollCenter();
$("isView").value="1";
//学习计时停止
timeFrame.window.stopTimer();
stopScaler();
//窗口置前
self.focus();
window.onblur=function (){self.focus();}
}
function stopScaler(){
//alert('stopScaler');
clearTimeout(tScaler);
}
function statScaler(){
var num = Math.round(Math.random()*9) + 11;//Math.floor(Math.random()*0) + 1;//产生一个 10-20之间的随机数
//alert(num);
tScaler = setTimeout("Time()",num * 60 * 1000);//根据随机数分钟数显示 IFrame ,在 IFrame 中提交时间//
$("isView").value="0";
window.onblur=function (){}
}
g_blnCheckUnload = true;
window.onbeforeunload = function() {
if(g_blnCheckUnload)
{
return '点"确定"结束学习,本次学习时间不会累计。点"取消"可继续学习。';
}
}
function cg()
{
timeFrame.window.stopTimer();
min($("btn"));
alert('更新学习时间成功!');
timeFrame.window.DoConverseCallTimer();
stopScaler();
statScaler();
}
function isView0()
{
$("isView").value="0";
}
function setPrompt(itype)
{
if(itype=="0")
{
timeFrame.window.document.getElementById("glowtext").innerHTML="更新学习时间中请等待...";
}
else
{
timeFrame.window.document.getElementById("glowtext").innerHTML="";
}
} 表示不懂delphi,帮忙顶一下!!!! 好多
页:
[1]