how to load a js file and execute it on CEF

心已入冬 提交于 2021-02-19 08:45:35

问题


I use CEF(chromium ebedded Framework) load a html page:

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

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:)


回答1:


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.



来源:https://stackoverflow.com/questions/29191363/how-to-load-a-js-file-and-execute-it-on-cef

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!