open source guy
open source guy

Reputation: 2787

how load javascript from local computer in pyside qwebview?

my files

messi_fan.py
barcelona_fan.html
jq.js

in same directory.

messi_fan.py

        f = open('barcelona_fan.html', 'r')
        html = f.read()
        f.close()
        self.webView = QWebView()
        self.webView.setHtml(html, baseUrl=QUrl('http://local'))
        self.webView.show()

barcelona_fan.html

<script type="text/javascript" src = "jq.js"></script>

my problem is jquery not loading in Qwebview. if i use like this in barcelona_fan.html

<script type="text/javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>

everything would work. but i want to load .js file from local.How can i do this?

Upvotes: 1

Views: 1701

Answers (1)

Jay
Jay

Reputation: 73

Let the baseUrl look to the local directory:

path = "c:\\foo\\bar"
self.webView.setHtml(html, baseUrl = QUrl().fromLocalFile(path))

BTW: if needed, don't forget:

self.webView.settings().setAttribute(QWebSettings.LocalContentCanAccessRemoteUrls, True)

Upvotes: 2

Related Questions