1

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?

0

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.