DELPHI如何调用页面里的JS

var
js: OleVariant;
str: string;
begin
js := CreateOleObject('ScriptControl'); // 创建组件
js.Language := 'JavaScript'; // 指定组件所使用的语言,也可以是VBScript
js.AddCode(Memo1.Text); // 加入JS代码,如上面的代码
str := js.Eval('getTime()');// getTime() function from JS
ShowMessage(str);

end;

//执行网页中的Js可以抄,但是调试网页中的Js就难道大了。推荐使用火狐浏览器,里面有一个Js格式化插件。很好调试!



Memo1.text内容

function getTime(){
var d, s = "";
var c = "";
d = new Date();
s += d.getYear()+c;
s += (d.getMonth() + 1) + c;
s += d.getDate() + c;
s += d.getHours() + c;
s += d.getMinutes() + c;
s += d.getSeconds() + c;
s += d.getMilliseconds();
return s;
}

出处:http://zhidao.baidu.com/question/402669882.html

posted @ 2012-12-08 11:33  stma  阅读(536)  评论(0)    收藏  举报