PDA

View Full Version : QWebView & Pop Up Windows



NicholasSmith
12th July 2010, 17:16
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!

wysota
12th July 2010, 18:18
What is exactly that you want to do? What's wrong with the default implementation of that method?

NicholasSmith
12th July 2010, 18:30
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?

wysota
12th July 2010, 22:26
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.

NicholasSmith
13th July 2010, 08:17
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.

girishgowda
13th July 2010, 11:54
Hi,

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

-Girish

NicholasSmith
13th July 2010, 12:06
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::JavascriptCanOpenWindow s, true);

ehsannmahdavi
1st April 2014, 09:03
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::JavascriptCanOpenWindow s,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???


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.