May 29, 2011

situ117 situ117
Lab Rat
42 posts

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

May 31, 2011

mbrasser mbrasser
Lab Rat
452 posts

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

May 31, 2011

situ117 situ117
Lab Rat
42 posts

Hi,

URL you sent has an invalid bug id.

EDIT: The correct URL is: https://bugs.webkit.org/show_bug.cgi?id=48415

May 17, 2012

CMGeorge CMGeorge
Lab Rat
16 posts

I had the same problem.
My “Fix” is this function:

  1. function checkForAnchor(scrollObject,webOject,url){
  2.         var a = new String(url);
  3.         if (a.split("#").length > 1){
  4.             var textPosition = webOject.evaluateJavaScript("document.getElementById('"+a.split("#")[1]+"').getClientRects()");
  5.             if (textPosition == 'undefined'){
  6.                 evaluateJavaScript('function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue){\
  7.                                        var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);\
  8.                                        var arrReturnElements = new Array();\
  9.                                        var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)", "i") : null;\
  10.                                        var oCurrent;\
  11.                                        var oAttribute;\
  12.                                        for(var i=0; i<arrElements.length; i++){\
  13.                                        oCurrent = arrElements[i];\
  14.                                        oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);\
  15.                                        if(typeof oAttribute == "string" && oAttribute.length > 0){\
  16.                                        if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){\
  17.                                        arrReturnElements.push(oCurrent);\
  18.                                        }\
  19.                                        }\
  20.                                        }\
  21.                                        return arrReturnElements;\
  22.                                   }')
  23.                 textPosition = webOject.evaluateJavaScript('getElementsByAttribute(document,"*", "title", "'+a.split("#")[1]+'")[0].getClientRects()')
  24.             }
  25.             if (textPosition != undefined){
  26.                 scrollObject.contentY = textPosition[0]["top"];
  27.             }
  28.         }
  29.     }

After this, on webView call:
  1.  onLoadFinished: {
  2.                         checkForAnchor(flickable,pageViewer,url);
  3. }

I know is a old post, but maybe will help someone in the future.

Happy Qt-ing

 Signature 

iOS & Qt Developer
Happy Qt-ing

 
  ‹‹ How to drag dynamic object in Qml?      QML ListView + ScrollArea ››

You must log in to post a reply. Not a member yet? Register here!