[PyQt] evaluateJavaScript on every page
Peter Irbizon
peterirbizon at gmail.com
Wed Apr 2 11:08:31 BST 2014
Hi, it looks it works now. I edited my code with new lines:
def __init__(self, url):
....
....
self.jQuery = """
your javascript code here
"""
self.view.loadProgress.connect(self.setProgress)
def setProgress(self, p):
self.view.page().mainFrame().evaluateJavaScript(self.jQuery)
2014-04-01 0:27 GMT+02:00 Peter Irbizon <peterirbizon at gmail.com>:
> 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/20140402/ae63f688/attachment.html>
More information about the PyQt
mailing list