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!
Re: QWebView & Pop Up Windows
What is exactly that you want to do? What's wrong with the default implementation of that method?
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?
Re: QWebView & Pop Up Windows
Quote:
Originally Posted by
NicholasSmith
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.
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.
Quote:
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.
Re: QWebView & Pop Up Windows
Hi,
Could you please try this setting on the QWebView->page()
QWebSettings::JavascriptCanOpenWindows
-Girish
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
Quote:
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);
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
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.