Results 1 to 4 of 4

Thread: QWebView: apply an external javascript when a page loads

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QWebView: apply an external javascript when a page loads

    Have tryed the following code:

    Qt Code:
    1. void MainWindow::applyScript()
    2. {
    3. QString javascript = "(function () { dl=document.links; for(i=0;i<dl.length;++i){ if(dl[i].href.substr(-4)==\".pdf\"){ dl[i].href=\"http://docs.google.com/viewer?url=\"+dl[i].href; } } })();";
    4. qDebug() << ui->webView->page()->currentFrame()->evaluateJavaScript(javascript).toString();
    5. }
    To copy to clipboard, switch view to plain text mode 

    but I got an empty string.
    Giuseppe CalÃ

  2. #2
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QWebView: apply an external javascript when a page loads

    Solved! the correct javascript to insert is:

    Qt Code:
    1. QString javascript = "dl=document.links; for(i=0;i<dl.length;++i){ if(dl[i].href.substr(-4)==\".pdf\"){ dl[i].href=\"http://docs.google.com/viewer?url=\"+dl[i].href; } }";
    To copy to clipboard, switch view to plain text mode 
    Giuseppe CalÃ

Similar Threads

  1. Speed up QWebview javascript
    By Diegol in forum Qt for Embedded and Mobile
    Replies: 5
    Last Post: 23rd March 2012, 11:10
  2. Debugging JavaScript from QWebView
    By thiagoalencar22 in forum Qt Programming
    Replies: 0
    Last Post: 30th October 2009, 11:12
  3. External Javascript file not loading initially
    By bkudrle in forum Qt Programming
    Replies: 0
    Last Post: 13th March 2009, 17:05
  4. how Adding JavaScript to QWebView
    By Houda.Qt4 in forum Qt Programming
    Replies: 9
    Last Post: 12th July 2008, 22:44
  5. Replies: 1
    Last Post: 27th November 2007, 10:10

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
  •  
Qt is a trademark of The Qt Company.