Results 1 to 4 of 4

Thread: QWebElement::evaluateJavaScript strange behaviour

  1. #1
    Join Date
    May 2009
    Posts
    133
    Thanks
    10
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QWebElement::evaluateJavaScript strange behaviour

    Hi

    Variant A does not work but variant B works.
    What's the reason?

    Qt Code:
    1. QWebElement doc = frame()->documentElement();
    To copy to clipboard, switch view to plain text mode 

    // variant A

    Qt Code:
    1. doc.findFirst("input[id='someId']").evaluateJavaScript("click()");
    To copy to clipboard, switch view to plain text mode 

    // variant B

    Qt Code:
    1. doc.findFirst("input[id='someId']").evaluateJavaScript("document.getElementById('someId').click()");
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWebElement::evaluateJavaScript strange behaviour

    What if you do this.click()?

  3. #3
    Join Date
    May 2009
    Posts
    133
    Thanks
    10
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWebElement::evaluateJavaScript strange behaviour

    This works. Thanks.

    Before I had been using QWebElement::function() which did not get into public API and it was enough to call it with "click" argument. It looks like it was executing js method in context (on behalf) of the element by default.

  4. #4
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWebElement::evaluateJavaScript strange behaviour

    I found this.click() doesn't work for other elements like DIV.
    I used this workaround:

    Qt Code:
    1. evaluateJavaScript("var evObj = document.createEvent('MouseEvents');evObj.initEvent( 'click', true, true );this.dispatchEvent(evObj);")
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Strange behaviour with QPen
    By franco.amato in forum Qt Programming
    Replies: 4
    Last Post: 19th January 2010, 05:51
  2. QMainWindow - strange behaviour
    By franco.amato in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2009, 23:44
  3. Need help: Strange behaviour
    By navi1084 in forum Qt Programming
    Replies: 3
    Last Post: 14th November 2008, 04:03
  4. very strange behaviour
    By regix in forum Qt Programming
    Replies: 23
    Last Post: 20th July 2006, 17:38
  5. [Qt 4.1] Strange behaviour with QTableView
    By fane in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2006, 06:17

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.