lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 20 February 2013 15:22, Rena <hyperhacker@gmail.com> wrote:
> Right now I'm trying to figure out how to find the position and size
> of a DOM element. What I want to do is position another application's
> window so that it covers an element in the document. It looks like
> there's a get_dom_document() method, but the object it returns isn't
> documented.

You can do this in lqt like this:

	require 'qtcore' require 'qtgui' require 'qtwebkit'

	local A = QApplication(1,{'WebkitTest'})
	local W = QWebView()
	W:load(QUrl('http://google.com')) -- load the Google main page
	W:connect('2loadFinished(bool)', function(self, ok)
		if ok then -- after it is loaded
			local F = W:page():mainFrame() -- get the main frame
			local inputBox = F:findFirstElement('input[name=q]') -- find the input box
			local r = inputBox:geometry()
			print(r:x(), r:y(), r:width(), r:height()) -- print its location on
the page relative to the parent frame
		end
	end)
	W:show()
	A.exec()

Everything is well documented in the Qt docs [1].

[1] http://doc.qt.digia.com/stable/qtwebkit.html

> Ultimately I'll want to communicate between my Lua code and the
> Javascript running on the page too, but it doesn't look like there's
> an API provided for that, or even to intercept resource loading (so JS
> could request a "page" from some made-up protocol, and the page
> contents be the response).

This also works well in lqt, just use QWebFrame::evaluateJavaScript(code):

	F:evaluateJavaScript('alert("Hello from Lua!");')