Results 1 to 8 of 8

Thread: QWebView & Pop Up Windows

  1. #1
    Join Date
    Jan 2009
    Posts
    31
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QWebView & Pop Up Windows

    I've had a bit of a search and not really found an answer, and the demo-browser example doesn't seem very clear on what I need.

    Essentially I have a Dialog window with a WebView, the website contains javascript to pop up windows so I've followed what's recommended and subclassed QWebView and now I'm some what baffled. I know I'm meant to reimplement createWindow(..) but I'm completely unsure on what to actually implement within it. Do I simply create a new QWebView? (which I've tried and I get a app crash), or do I create a new QDialog with a QWebView or something else?

    Any help would be much appreciated, normally I'd just google the function name for an example but unfortunately it gets me 30 pages of qwebview.cpp!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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 & Pop Up Windows

    What is exactly that you want to do? What's wrong with the default implementation of that method?
    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
    Jan 2009
    Posts
    31
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QWebView & Pop Up Windows

    I have an application that loads a webpage (an intranet), that site uses JavaScript to pop open new windows. When I tried with QWebView it didn't really do much, then everything I read suggested I had to subclass it and reimplement the createWindow function. Has my Googling lead me astray?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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 & Pop Up Windows

    Quote Originally Posted by NicholasSmith View Post
    Has my Googling lead me astray?
    I think so... Reimplementing this method makes sense if you want to prevent a window from being created or if you want to customize it in some way. You can reimplement this method by sending a message to the console and calling the base class implementation to see if WebKit calls it for the popup at all.
    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.


  5. #5
    Join Date
    Jan 2009
    Posts
    31
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QWebView & Pop Up Windows

    Thanks, given me something to think about, unfortunately the documentation is where I got the subclassing to get popups to work idea so back to the drawing board.

    If you want to provide support for web sites that allow the user to open new windows, such as pop-up windows, you can subclass QWebView and reimplement the createWindow() function

    Ah hah, I've now managed to get it to create a new window properly, now just trying to work out how I trap the QUrl requested.
    Last edited by NicholasSmith; 13th July 2010 at 10:28.

  6. #6
    Join Date
    Mar 2010
    Location
    Kawasaki, Japan
    Posts
    13
    Qt products
    Qt/Embedded Qt Jambi
    Platforms
    Symbian S60

    Default Re: QWebView & Pop Up Windows

    Hi,

    Could you please try this setting on the QWebView->page()
    QWebSettings::JavascriptCanOpenWindows

    -Girish

  7. #7
    Join Date
    Jan 2009
    Posts
    31
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QWebView & Pop Up Windows

    Hi, I've tried that with the QWebView, and with my WebView subclass and it didn't seem to help

    Edit: Just to make it easier here's what I'm using for QWebView

    QWebSettings *settings = m_ui->webView->settings();
    settings->setAttribute(QWebSettings::JavascriptEnabled, true);
    settings->setAttribute(QWebSettings::PluginsEnabled, true);
    settings->setAttribute(QWebSettings::AutoLoadImages, true);
    settings->setAttribute(QWebSettings::JavaEnabled, false);
    settings->setAttribute(QWebSettings::JavascriptCanOpenWindo ws, true);
    Last edited by NicholasSmith; 13th July 2010 at 12:48.

  8. #8
    Join Date
    Apr 2014
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: QWebView & Pop Up Windows

    Dear NicholasSmith, hi
    I am having the same problem,

    I had enabled all JavaScript settings as below:
    ui.webView->page()->setLinkDelegationPolicy(QWebPage:: DelegateAllLinks);//Handle link clicks by yourself
    ui.webView->settings()->setAttribute(QWebSettings::JavascriptEnabled,true );
    ui.webView->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindo ws,true);
    ui.webView->settings()->setAttribute( QWebSettings::JavascriptCanAccessClipboard,true);
    ui.webView->settings()->setAttribute( QWebSettings::JavascriptCanCloseWindows,true);
    ui.webView->settings()->setAttribute( QWebSettings::JavascriptCanOpenWindows,true);
    ui.webView->settings()->setAttribute( QWebSettings::PluginsEnabled,true);
    ui.webView->settings()->setAttribute( QWebSettings::JavaEnabled,true);
    ui.webView->settings()->setAttribute( QWebSettings::JavascriptEnabled,true);
    ui.webView->settings()->setAttribute( QWebSettings::AutoLoadImages,true);

    but it still doesn't work.
    I searched the qt docs and I've read this: "If you want to provide support for web sites that allow the user to open new windows, such as pop-up windows, you can subclass QWebView and reimplement the createWindow() function"

    then I followed this post and I saw that you have wrote: "Ah hah, I've now managed to get it to create a new window properly, now just trying to work out how I trap the QUrl requested."

    Seems that you've got the answer.

    Would you please give me the hint???

    Quote Originally Posted by NicholasSmith View Post
    Thanks, given me something to think about, unfortunately the documentation is where I got the subclassing to get popups to work idea so back to the drawing board.




    Ah hah, I've now managed to get it to create a new window properly, now just trying to work out how I trap the QUrl requested.

Similar Threads

  1. Replies: 8
    Last Post: 3rd September 2013, 09:51
  2. QWebView on S60
    By stepic in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 22nd April 2010, 20:40
  3. QWebView
    By Magu in forum Newbie
    Replies: 1
    Last Post: 22nd October 2009, 09:06
  4. QWebView
    By giusepped in forum Qt Programming
    Replies: 3
    Last Post: 18th March 2009, 05:32
  5. QWebView
    By SailinShoes in forum Qt Programming
    Replies: 0
    Last Post: 16th January 2009, 07:22

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.