[Qt-interest] Scroll to anchor in QWebView?
Tony Rietwyk
tony.rietwyk at rightsoft.com.au
Thu Jan 28 09:12:44 CET 2010
Hi Eric,
You should be able to modify this javascript snippet to achieve what you
want. Its quite old and worked in IE and Firefox, but has not been tested
in WebKit. This assumes that you can include your own javascript in the
page somehow:
function GotoPageAnchor() {
var oElement;
var iOffset;
// When the user has filled in a form, we sometimes want the next page to
scroll down,
// but this can't be done from within the application. So it sets
"gPageAnchor" to the
// ID of the element to be scrolled to. Then this routine is called as
part of PageLoad event.
//
// Doing the scroll directly didn't work, but using a timer did.
//
// Instead of scrolling the element hard against the top of the browser
window, a 100 pixel
// margin allows the user to see a bit of the previous context.
if (document.getElementById) {
if (typeof(gPageAnchor) == "string") {
oElement = document.getElementById(gPageAnchor);
if (oElement) {
iOffset = oElement.offsetTop;
while (oElement.offsetParent) {
oElement = oElement.offsetParent;
iOffset += oElement.offsetTop;
}
// alert( "Offset of " + gPageAnchor + " = " + (iOffset) );
if (iOffset > 100) {
iOffset -= 100;
}
setTimeout( "scrollTo(0,"+iOffset+")", 20 );
}
}
}
}
Regards,
Tony
-----Original Message-----
Hello All,
I would like to know if anyone knows of a way to force a QWebView to scroll
to an anchor in the web page that it is currently showing?
Thanks,
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100128/fd76b1f6/attachment.html
More information about the Qt-interest-old
mailing list