Results 1 to 4 of 4

Thread: QWebView and evaluateJavaScript

  1. #1
    Join Date
    Aug 2012
    Posts
    10
    Thanks
    1

    Default QWebView and evaluateJavaScript

    Hi there,

    I want to write a programme with several QWebView's. So I created few QWebView's and load for every View another HTML Site. Then I want to delete from every site HTML links. I do this after loadFinished(bool) is emitted from QWebView with evaluateJavaScript() function.

    Qt Code:
    1. web_view->page()->mainFrame()->evaluateJavaScript("$('a').each( function () { $(this).removeAttr('href'); } )");
    To copy to clipboard, switch view to plain text mode 

    I reconginze that the function evaluateJavaScript() only works at its own object but if I load these HTML sites only links from the last loaded HTML are removed.


    I that a normal behviour or how can I fix it that links are removed on every HTML site in a QWebView?

  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: QWebView and evaluateJavaScript

    What do you mean by "every HTML site in a QWebView"?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2012
    Posts
    10
    Thanks
    1

    Default Re: QWebView and evaluateJavaScript

    Qt Code:
    1. QFile file1, file2, file3;
    2.  
    3. file1.setFileName("site1.html");
    4. file1.open(QIODevice::ReadOnly);
    5.  
    6. file2.setFileName("site2.html");
    7. file2.open(QIODevice::ReadOnly);
    8.  
    9. file3.setFileName("site3.html");
    10. file3.open(QIODevice::ReadOnly);
    11.  
    12. QWebView webview1 = new QWebView();
    13. webview1->setContent(file1.readAll();
    14.  
    15. QWebView webview2 = new QWebView();
    16. webview2->setContent(file2.readAll();
    17.  
    18. QWebView webview3 = new QWebView();
    19. webview3->setContent(file3.readAll();
    20.  
    21.  
    22. //...
    23. //if page is loaded and loadFinished(bool) signal is emitted
    24. //...
    25. mweb_view1->page()->mainFrame()->evaluateJavaScript("$('a').each( function () { $(this).removeAttr('href'); } )");
    26. //...
    27. mweb_view2->page()->mainFrame()->evaluateJavaScript("$('a').each( function () { $(this).removeAttr('href'); } )");
    28. //...
    29. mweb_view3->page()->mainFrame()->evaluateJavaScript("$('a').each( function () { $(this).removeAttr('href'); } )");
    To copy to clipboard, switch view to plain text mode 

  4. #4
    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: QWebView and evaluateJavaScript

    That doesn't really answer my question...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. webkit evaluatejavascript
    By huyanke in forum Newbie
    Replies: 1
    Last Post: 13th May 2011, 12:27
  2. QWebElement evaluateJavaScript problem
    By Talei in forum Newbie
    Replies: 0
    Last Post: 10th March 2011, 04:38
  3. Replies: 2
    Last Post: 16th June 2010, 15:42
  4. QWebFrame evaluateJavaScript
    By bunjee in forum Qt Programming
    Replies: 2
    Last Post: 2nd September 2009, 07:55
  5. Problem with evaluateJavaScript()
    By piotr.dobrogost in forum Qt Programming
    Replies: 0
    Last Post: 26th August 2009, 19:36

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.