如何加载js文件并在CEF上执行 [英] how to load a js file and execute it on CEF

查看:149
本文介绍了如何加载js文件并在CEF上执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CEF(铬嵌入框架)加载html页面:

 <!DOCTYPE html>< html>< head></head><身体>< script src ="phantom-limb.js" type ="text/javascript"></script></body></html> 

,它可以正常工作.现在,我将页面修改如下:

 <!DOCTYPE html>< html>< head></head><身体></body></html> 

然后在cef加载它之后,我使用cef的ExecuteJavaScript方法执行相同的phantom-limb.js,但是什么也没有出现.

如何加载js文件并执行,或者js文件有一定限制?

thx:)

解决方案

如您在

and it works ok. now, I modify the page as follow:

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
    </body>
</html>

and after cef loaded it, I use cef's ExecuteJavaScript method to execute the same phantom-limb.js, but nothing appear.

how can I load the js file and execute, or, the js file has some limit?

thx:)

解决方案

As you can see at the end of the source code of you JS file, the startOnLoad config parameter is set to true by default.

In this way a listener to the DOMContentLoaded is added, which is never called because your page is already loaded.

So, you just have to append the line start(); to your source code, then call your ExecuteJavaScript and it will work even after the page is loaded.

这篇关于如何加载js文件并在CEF上执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆