IHTMLDocument2使用ExecScript执行js脚本,如何取得脚本的返回值?(100分)

  • 主题发起人 主题发起人 sth2007
  • 开始时间 开始时间
S

sth2007

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure ExecuteScript(doc: IHTMLDocument2; script: string; language: string) ;
begin
if doc <> nil then
begin
if doc.parentWindow <> nil then
doc.parentWindow.ExecScript(script, Olevariant(language)) ;
end;
end;
script = 'return 999;'
ExecuteScript(WebBrowser1.Document as IHTMLDocument2, script, 'javascript');
 
自己顶自己!
 
前一段也在研究这个....结果是 delphi的webbrowser的ExecScript无法给出script的返回值....

最后只好把script函数写入webbrowser然后Navigate('javascript:函数名')再取outerText
 
hs-kill你是说讲返回数据卸载document里面,然后再对twebbrowser进行解析处理是么?
 
是先加载正常的页面,因为script是写在页面里的,然后再用Navigate方式执行这个script,这样Document里的内容就是script的返回值了,没办法....

网上找了好久了,用.net和C#有办法得到ExecScript的返回值,delphi好像不行,至少我试了没结果
 
学习一下,
 
net,c#用的也是叫做‘ExecScript()’函数名还是别的?我了解了解!
 
这个文章有介绍,你看看吧....
http://blog.csdn.net/cui55/archive/2006/07/06/884506.aspx
 
看了,似乎只有将数据卸载document里面中这方法!
 
是啊...我为这个问题也郁闷好久了
 
问 楼上一个问题

怎么样用IHTMLDocument2直接取得一个已知URL网页的源码?

一般的方式是先 Webbrower.Navigate(Url)
然后IHtmlDocument2(WebBrowser1.Document) 就可以取得网页源码。

现在 我不想在Webbrower里显示Url对应的网页,只想取得网页对应的源码。谢谢。
 
那你用idhttp取源码不就行了......

要是分析连接...相对路径是个麻烦,前几天我刚为这事发愁,你自己看看帖子吧
http://www.delphibbs.com/delphibbs/DispQ.asp?LID=3926011
 
是的,直接对源代码进行分析的话,那么绝对路径是个大问题!
 
来自:hs-kill, 时间:2008-11-6 12:19:57, ID:3928343
那你用idhttp取源码不就行了......

===
就是不要用idhttp。
 
去网上找一个scriptrr有例子的
=============
Script Runner
=============

Version : 1.00
Release Date : 24 Nov 1998
Author : Sing Wong

Copyright (C) 1998
E-mail : wongsing@netvigator.com
(Comments or sugguestions are always welcome)

===========
Description
===========
Demo program writen in Delphi 4.0, shows how to using Microsoft Script
Control v1.0 in Delphi, through Object Linking and Embedding (OLE)
interface. Is able to interpret VB or Java Script. And can be a utility
applet as well, just likes what Windows Scripting Host does in Windows
98.
Should be OK to run on Delphi 2.x / 3.x, but I have not tried before.

=====
Usage
=====
You have to install Microsoft Script Control v1.0, before you can run
this program, after that, a file called MSScript.ocx would be found on
your machine, at system path of Windows, or anywhere, as the case may
be. If you do not have it, you may down load it from web page :

http://www.Microsoft.com/Scripting/ScriptControl/Default.htm

==============
Known Problems
==============
-Two or more subroutine with same name call be added to script engine
at the same.
-More than one arguments in subroutine, which acts as a start up one,
is not handled in this version, even it's possible.

========
Contents
========
Readme.txt - This file
ScriptRunner.* - Project file of Script Runner
FormMain.* - Main form / unit in project
FormStartUp.* - Start up form, part of Script Runner
SRDemo.txt - Sample script file writen in VB Script

======
Charge
======
Totally free of charge, including source code.

==========
DISCLAIMER
==========
THIS SOFTWARE AND THE ACCOMPANYING FILES ARE PROVIDED "AS IS" WITHOUT
WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS
FOR A PARTICULAR PURPOSE.

Best regards!
Sing Wong
(* Sorry for my bad English! *)
 
TO cxz9:

收到你的答复了,还没用,应该有其用处吧!
 
TScriptControl我用过...直接从ActiveX里添加就行了...
不过这个有点麻烦,在IE里直接运行页面里的script函数名就行了
如果用TScriptControl却要找到script相关的对象和过程啊,很多script都是写到js里的,需要自己分析页面
 
后退
顶部