WebKit: how to force plugins (flash) to stop
Hi there,
I'm using QtWebkit module to integrate a simple browser inside an own application.
When I "switch off" the browser, I'd like the plugin as well to stop working.
For example, if there's a flash video in playback when I close the browser window, I'd like to force stopping the flash plugin to render it.
Instead I can still listen to the audio playback.
I tried with:
webPage->settings()->setAttribute(QWebSettings::PluginsEnabled, false);
but this call only has effect when a new url is loaded.
Any hints?
Thanks,
Ricky
Re: WebKit: how to force plugins (flash) to stop
Use QtWebKit.QWebPage.mainFrame().findAllElements() (using pyqt speak replace periods with colon for C) this gives you a QWebElementCollection
which leads to a QWebElement and then look for tagName() == 'EMBED' and do QWebElement .removeFromDocument ()
This will I suppose remove all plugin type elements from the page. You could do a more selective search using QWebElement.attributeNames ( ) .
Here is snippet from my pyqt webkit browser I have it run at same time as I stop the javascript.
absltlall = QtCore.QString('*')
allinframe =crnt.Mpage.mainFrame().findAllElements ( absltlall)
for z in allinframe:
if z.tagName() == 'EMBED':
z.removeFromDocument ()
The above seems to work OK for me. . It is not completely pretty. Sometimes the element is removed and sometimes it is replaced with a blank space.
I do not understand that CSS selector selector stuff and maybe you do not have to go through all the elements but use something more intelligent than my QtCore.QString('*') in the findAllElements ( )
Re: WebKit: how to force plugins (flash) to stop
If you don't need the page anymore then delete it. Closing a webview will not cause it to be deleted automatically.
Re: WebKit: how to force plugins (flash) to stop
Thank you for your replies, both methods work for me.
Second is quick and clean, the only drawback is that it erases the history.
Ricky