KHTMLPart executeScript() infinite loop

sebaro sebaro at apropo.ro
Thu Apr 14 09:13:46 BST 2011


Hello

I have a problem with executeScript() in a KHTMLPart.
I want to execute external scripts in websites.
The folowing does the job:

----------------------------------------------------------
...
m_part = dynamic_cast<KHTMLPart *>(parent);
connect(m_part,SIGNAL(completed()),this,SLOT(slotApplyScript()));
...
void slotApplyScript()
{
...
    if (!scriptContent.isEmpty()) {
       m_part->executeScript(scriptContent);
     }
}
----------------------------------------------------------

but if the script contains something like:

-----------------------------
document.getElementById('someElID').innerHTML = '<object  
data="someDataPath"></object>';
document.getElementById('someElID').innerHTML = '<embed  
src="someDataPath"></embed>';
document.getElementById('someElID').innerHTML = '<iframe  
src="someDataPath"></iframe>';
-----------------------------
where someDataPath is a path to a multimedia file or a web page document,

KHTMLPart loads, it executes the script,
then it seems like when loading "someDataPath"
KHTMLPart executes the script again, therefore an infinite loop.

I'm using konqueror-4.4/qt-4.6 on Gentoo.

I also sent an email to kde-devel and got this answer:

> Maksim's answer:

> "It should only happen if someDataPath is html (or if embed is really  
> iframe).But if you want to only run for top-levels (which is unclear  
> whether itshould), you should see KHTMLPart::parentPart()."

KHTMLPart apidocs say:

KHTMLPart::parentPart()
Returns a pointer to the parent KHTMLPart if the part is a frame in an  
HTML frameset.

I don't know how this could help me.


Thank you.


Kind Regards,

Sebastian Luncan
Powered by Tux & GNU




More information about the kfm-devel mailing list