Important: Please read the Qt Code of Conduct -

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 and click on Definition link in table of contents, WebView does not respond.

    I had a look at QML Web Browser demo ( ) 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.

  • Hi,

    The second paragraph sounds like [EDIT: fixed URL]. I'm not sure if there are any workarounds at the moment.


  • Hi,

    URL you sent has an invalid bug id.

    EDIT: The correct URL is:

  • 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))){
    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: {

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

    Happy Qt-ing

Log in to reply