Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. QGraphicsWebView injecting script does not work
Forum Updated to NodeBB v4.3 + New Features

QGraphicsWebView injecting script does not work

Scheduled Pinned Locked Moved Qt WebKit
2 Posts 1 Posters 983 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.
  • E Offline
    E Offline
    elkvis
    wrote on last edited by
    #1

    I'm trying to inject a bit of javascript to handle the window.onload event, and I can't seem to get it to work.

    I connect to the loadFinished signal, and get the <head> tag, to which I try to add javascript code using the following slot function:

    @
    void Html5ApplicationViewerDerived::InjectJavascript()
    {
    QWebElement head = webView()->page()->mainFrame()->findFirstElement("head");
    QString scriptText = "<script>window.onload = function() { alert('Foo!'); }</script>";
    head.appendInside(scriptText);
    }
    @

    When I inspect the document, the new <script> tag does not appear at all. I am able to append to the body element with other types of tags, such as <label>, but I cannot seem to add to the <head> element. If I get a script element inside <head>, I can append to that, but the new script does not execute. I suspect that the loadFinished signal is emitted after the window.onload event happens. There is no guarantee that any script element will exist in any particular html file that I load, so I need to be able to create one.

    1 Reply Last reply
    0
    • E Offline
      E Offline
      elkvis
      wrote on last edited by
      #2

      Update:

      after some more testing, I found that QGraphicsWebView's loadFinished signal does not get sent until after window.onload has completed.

      QWebFrame's initialLayoutCompleted signal gets sent after window.onload, but seems to run concurrently with it, not waiting for it to finish.

      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