如何在TWebbrowser中获取JS脚本控制台输出?

时间:2016-06-09 14:34:25

标签: delphi mshtml twebbrowser

我想在TWebbrowser中运行一个javascript代码并获取它的控制台输出。例如,如果我在控制台中运行此代码:

var a = 2; var b = 3; var c = a +b ; console.log('The result is '+ c); 

我在控制台上获得此输出:

The result is 5

我用来运行带有TWebbrowser的JS脚本的代码是:

twebbrowser1.navigate('javascript:var a = 2; var b = 3; var c = a +b ; console.log('The result is '+ c);');

它有效,但我不知道如何获得控制台输出。有办法吗?

提前致谢!

1 个答案:

答案 0 :(得分:7)

根据MSDN,您的(Delphi)应用程序看起来需要实现This blog post界面。

然后,您可以将IDeveloperConsoleMessageReceiver的对象实例连接到浏览器的当前文档。查询TWebBrowser.Document接口的IDM_ADDCONSOLEMESSAGERECEIVER属性,然后调用其Here is Apple's documentation方法发出function deleteObjectGraph(object, type, realm) { let objectSchema = realm.schema.find((objectSchema) => objectSchema.name == type); // delete all child objects for (let propName in objectSchema.properties) { let prop = objectSchema.properties[propName]; // for list properties delete all elements and their children if (prop.type == 'list') { object[propName].forEach((listObject) => deleteObjectGraph(listObject, prop.objectType, realm); ); } // for object properties delete object and all children if (prop.type == 'object' && object[propName] != null) { deleteObjectGraph(object[propName], prop.objectType, realm); } } // delete the object realm.delete(object); } 命令。

试试看,如果你遇到困难,请再试一次。