[PyQt] evaluateJavaScript on every page
Peter Irbizon
peterirbizon at gmail.com
Mon Mar 31 23:27:58 BST 2014
Hi guys,
I am using evaluateJavaScript to change some JS values in my case
window.navigator. It works pretty well on first visited page
http://something.tld/first.php but when I click on any link on that page
and go to second.php it stops to be in effect.
How can I do it to stay this javascript in effect for every visited
(navigated, clicked) page from my application?
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from PyQt4 import QtCore, QtGui, QtWebKit
getJsValue = """
window.navigator = {
appCodeName: 'MyApp',
appName: 'MyNewApp',
vendor: 'MyCompany'
}
"""
class myWindow(QtWebKit.QWebView):
def __init__(self, parent=None):
super(myWindow, self).__init__(parent)
self.page().mainFrame().evaluateJavaScript(getJsValue)
self.page().mainFrame().addToJavaScriptWindowObject("myWindow",
self)
self.loadFinished.connect(self.on_loadFinished)
self.load(QtCore.QUrl('http://something.tld/first.php'))
@QtCore.pyqtSlot(str)
def showMessage(self, message):
print "Message from website:", message
@QtCore.pyqtSlot()
def on_loadFinished(self):
#self.page().mainFrame().evaluateJavaScript(getJsValue)
pass
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
app.setApplicationName('myWindow')
main = myWindow()
main.show()
sys.exit(app.exec_())
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140401/7d2671eb/attachment.html>
More information about the PyQt
mailing list