Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    HTML link, style, and script elements are erroneously removed by QWebKit from the head element

    Qt WebKit
    2
    3
    1092
    Loading More Posts
    • 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.
    • P
      Pt_develop last edited by

      When I inspect the HTML loaded into webkit using the toHtml method (or the toOuterXml method) I find that the Qt webkit methods produce erroneous results for elements in the head element.

      For example, I used QWebView to display the following HTML:
      @
      <!DOCTYPE html>
      <html>
      <head>
      <title>head test</title>
      <meta charset="utf-8" />.
      <link href="sample.css" rel="stylesheet" />
      <script></script>
      <style>p{font-family:"Times New Roman";font-size:20px;}</style>
      </head>
      <body>
      <p>test paragraph</p>
      </body>
      </html>
      @

      When I try to inspect the loaded HTML using;
      @qDebug()<<ui->webView->page()->mainFrame()->toHtml();@

      I get the following result:
      @
      "<!DOCTYPE html><html><head>
      <title>head test</title>
      <meta charset="utf-8"></head><body>.
      <link href="sample.css" rel="stylesheet">
      <script></script>
      <style>p{font-family:"Times New Roman";font-size:20px;}</style>

      <p>test paragraph</p>

      </body></html>"
      @

      Notice that the <style> , <link> , and <<script> elements are all erroneously moved into the body element from the head element.

      Has anyone else encountered this. If so, do they have a solution?

      1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators last edited by

        maybe because there is a point after the meta-element which causes a parsing error and webkit tries to repair this.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply Reply Quote 0
        • P
          Pt_develop last edited by

          After doing some more investigation of the file I'd copied to form my test case I found some unexpected Unicode control characters after the meta tag that displayed as a dot(point). After removing these characters everything worked ok.

          Since I am constrained to using HTML generated elsewhere I'll have to preprocess the source HTML but I am a little surprised that WebKit didn't throw an error. In fact I'm now curious as to why WebKit processed a link element it thought was a child of the body element in violation of the specifications!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post