Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Unable to open webpage sections using WebView
Forum Updated to NodeBB v4.3 + New Features

Unable to open webpage sections using WebView

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 3.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    situ117
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        situ117
        wrote on last edited by
        #3

        Hi,

        URL you sent has an invalid bug id.

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

        1 Reply Last reply
        0
        • C Offline
          C Offline
          CMGeorge
          wrote on last edited by
          #4

          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

          iOS & Qt Developer
          Happy Qt-ing

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved