Trolltech Home | Qt4-preview-feedback Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt4-preview-feedback Archive, February 2008
QWebPage could use a findElement() function


Message 1 in thread

Right now, findText() is there to look for specific text, but there's no (at 
least no obvious) way to find an element if you know its ID.

Something like this could be useful:

bool QWebPage::findElement(const QString &id) {
	return currentFrame()->evaluateJavaScript(
		"var element=document.getElementById('" + id.replace("'", "\'") + "');"
		"if(element == null) {"
		"	0;"
		"	break;"
		"}"
		"var y=0;"
		"while(element!=null) {"
		"	y += element.offsetTop;"
		"	element = element.offsetParent;"
		"}"
		"window.scrollTo(0, y);"
		"1;").toUInt();
}


(there's probably a more elegant way to do it if you modify the QtWebKit code 
itself...)

Regards
bero

To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx