<div dir="ltr"><div>Hi guys, </div><div><br></div><div>I am using evaluateJavaScript to change some JS values in my case window.navigator. It works pretty well on first visited page <a href="http://something.tld/first.php">http://something.tld/first.php</a> but when I click on any link on that page and go to second.php it stops to be in effect.</div>
<div>How can I do it to stay this javascript in effect for every visited (navigated, clicked) page from my application? </div><div><br></div><div>#!/usr/bin/env python</div><div>#-*- coding:utf-8 -*-</div><div><br></div><div>
from PyQt4 import QtCore, QtGui, QtWebKit </div><div><br></div><div>getJsValue = """ </div><div>window.navigator = {</div><div> appCodeName: 'MyApp',</div><div> appName: 'MyNewApp',</div>
<div> vendor: 'MyCompany'</div><div>}</div><div>""" </div><div><br></div><div>class myWindow(QtWebKit.QWebView): </div><div> def __init__(self, parent=None):</div><div> super(myWindow, self).__init__(parent)</div>
<div> </div><div> self.page().mainFrame().evaluateJavaScript(getJsValue)</div><div> </div><div> self.page().mainFrame().addToJavaScriptWindowObject("myWindow", self)</div><div> self.loadFinished.connect(self.on_loadFinished)</div>
<div> self.load(QtCore.QUrl('<a href="http://something.tld/first.php'">http://something.tld/first.php'</a>))</div><div><br></div><div> @QtCore.pyqtSlot(str) </div><div> def showMessage(self, message):</div>
<div> print "Message from website:", message</div><div><br></div><div> @QtCore.pyqtSlot()</div><div> def on_loadFinished(self):</div><div> #self.page().mainFrame().evaluateJavaScript(getJsValue)</div>
<div> pass </div><div><br></div><div>if __name__ == "__main__":</div><div> import sys</div><div><br></div><div> app = QtGui.QApplication(sys.argv)</div><div> app.setApplicationName('myWindow')</div>
<div><br></div><div> main = myWindow()</div><div> main.show()</div><div><br></div><div> sys.exit(app.exec_())</div></div>