Unable to open webpage sections using WebView
Hi,
I’m trying to write a small browser in QML using WebView. In WebView, I am not able to switch sections on same page by clicking on links. For e.g. if I open http://en.wikipedia.org/wiki/Europe and click on Definition link in table of contents, WebView does not respond.
I had a look at QML Web Browser demo ( http://doc.qt.nokia.com/4.7-snapshot/demos-declarative-webbrowser.html ) which has same problems. If I click on a link which refers to some section on same page, instead of taking me to that section of page, Demo Browser takes me to top of the page.
3 replies
Hi,
The second paragraph sounds like https://bugs.webkit.org/show_bug.cgi?id=48415 [EDIT: fixed URL]. I’m not sure if there are any workarounds at the moment.
Regards,
Michael
Hi,
URL you sent has an invalid bug id.
EDIT: The correct URL is: https://bugs.webkit.org/show_bug.cgi?id=48415
I had the same problem.
My “Fix” is this function:
- function checkForAnchor(scrollObject,webOject,url){
- var a = new String(url);
- if (a.split("#").length > 1){
- var textPosition = webOject.evaluateJavaScript("document.getElementById('"+a.split("#")[1]+"').getClientRects()");
- if (textPosition == 'undefined'){
- evaluateJavaScript('function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue){\
- var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);\
- var arrReturnElements = new Array();\
- var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)", "i") : null;\
- var oCurrent;\
- var oAttribute;\
- for(var i=0; i<arrElements.length; i++){\
- oCurrent = arrElements[i];\
- oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);\
- if(typeof oAttribute == "string" && oAttribute.length > 0){\
- if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){\
- arrReturnElements.push(oCurrent);\
- }\
- }\
- }\
- return arrReturnElements;\
- }')
- textPosition = webOject.evaluateJavaScript('getElementsByAttribute(document,"*", "title", "'+a.split("#")[1]+'")[0].getClientRects()')
- }
- if (textPosition != undefined){
- scrollObject.contentY = textPosition[0]["top"];
- }
- }
- }
After this, on webView call:
- onLoadFinished: {
- checkForAnchor(flickable,pageViewer,url);
- }
I know is a old post, but maybe will help someone in the future.
Happy Qt-ing
You must log in to post a reply. Not a member yet? Register here!




