View Full Version : The access between WebView and HTML javascript

18th October 2011, 01:50

I have a question about WebView element.

I create a HTML file named "hfile.htm", and I use a WebView with the url property is "hfile.htm".

Now my main.qml is like:

import QtQuick 1.0
import QtWebKit 1.0

Rectangle {
width: 600
height: 400
WebView { id: webMap
anchors.fill: parent
url: "hfile.htm"
Rectangle { id: rec1
width: 100
height: 100
color: "red"

Can I change the color property of Rectangle rec1 from javascript in hfile.htm??

18th October 2011, 07:32
You probably can but this probably requires a lot of work. You'd need to expose some objects to the page handled by WebView and then have appropriate scripts on the page manipulate those objects. You'd need to use the javaScriptWindowObjects attribute from WebView.