开发者

How to edit a property on 'window', 'document'(width,height) from QtWebKit?

开发者 https://www.devze.com 2023-03-23 22:17 出处:网络
I tried to change like that(worked on the \'navigator\' object) page->mainFrame()->evaluateJavaScript(

I tried to change like that(worked on the 'navigator' object)

page->mainFrame()->evaluateJavaScript(
    "var navigator=new开发者_如何学运维 Object;"
    "navigator.someProperty=...");


In that case, I would use the signal javaScriptWindowObjectCleared

That kicks in just before load, when the window has been cleared.

You probably want to validate the origin before doing anything, though.

That being said - and I am not too sure what you want to achieve - I wouldn't manipulate the javascript scope like that. Maintaining and deploying javascript is easier than doing the same for C++. So, I would instead just expose a simple C++ object to the javascript scope (via addToJavaScriptWindowObject), and then have the javascript code test this object and do what it has to do.

Either way, hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消