![]() Registered Member ![]()
|
Hi,
I want to execute external scripts in websites. The folowing does the job:
but, if the script contains non empty "src" or "data" attributes, I'm getting a infinite loop. How can I solve this? Thanks.
Last edited by sebaro on Tue Jun 21, 2011 7:20 am, edited 1 time in total.
|
![]() Administrator ![]()
|
Have you tried attaching a debugger to Konqueror and generating a backtrace? It might be a bug in KHTML.
KDE Sysadmin
[img]content/bcooksley_sig.png[/img] |
![]() Registered Member ![]()
|
No. For a script like:
KHTMLPart loads the page, then it seems like is loading "someDataPath" like a new document too, so it executes the script, therefore the infinite loop. Adding:
it prints the script conntent indefinitely. I know very little qt/kde programming, I modified someone's konqueror plugin so I can execute scripts from a directory in some web pages I browse. Maybe it's the way KHTMLPart works and there's more to be done. Thanks! |
![]() Administrator ![]()
|
I would recommend sending an email to kde-devel@kde.org regarding this, as the developers of KHTML are likely going to know more about this issue..
KDE Sysadmin
[img]content/bcooksley_sig.png[/img] |
![]() Registered Member ![]()
|
I did send an email to kde-devel. They said I should use KHTMLPart::parentPart(), but this is for frames in an HTML frameset. They also said I should contact kfm-devel from now on. I did. Here, Michael Pyne asked me if I use the -ffast-math gcc flag, which I don't, and to use a JS debugger. What's to debug in this line?
Now I found there's Userscript (Greasemonkey like) for Konqueror 4 http://websvn.kde.org/trunk/playground/utils/khtml_userscript/ but with the same problem. Unfortunatly I don't think the project is maintain anymore. The last revision is from 13 months ago. I don't know who should I contact now. Thanks. |
![]() Registered Member ![]()
|
Have you considered a code refactor where you disconnect slotApplyScript once it is executed?
connect(post, SIGNAL(readSignature()), qapp, SLOT(quit()));
|
![]() Registered Member ![]()
|
It never gets disconnected. If I disconnect it, the script is applied once when opening an new tab/window and is not applied on refresh or when entering a new webpage in the same tab/window. |
![]() Registered Member ![]()
|
Sebaro, 1- I would avoid innerHTML for many reasons. If you absolutely need to embed an <object> dynamically, then this can be done without innerHTML and with createElement("object") and DOM 2 HTML http://www.w3.org/TR/DOM-Level-2-HTML/h ... ID-9893177 2- I also would set the type (content-type, mimeType) of the object. 3- You could do smaller tests involving the dynamic attachment of an <object> into such someElID. <object> can be almost anything: an <img>, an application, a multi-media content (video, audio, whatever) an HTML fragment, or HTML document. That reinforces the necessity to declare a type. 4- Your someElID must be a block-level box container (like <p> or <div>) since <object> is an inline-block replaced element. 5- In your code, you were also missing escaping the forward slash into the closing tag: Writing HTML in a SCRIPT Element http://htmlhelp.com/tools/validator/pro ... .en#script states " A common error (and the most common source of erroneous bug reports for the WDG HTML Validator) occurs when writing HTML tags within a SCRIPT element: " 6- if you want to execute external scripts, then why not just create a script object and then specify the src attribute accordingly? I can not really help you with the rest of your code, namely your slotApplyScript() function or as to why there is an infinite loop but I know DHTML and your DHTML code is not ideal. regards, Gérard |
![]() Registered Member ![]()
|
Gérard, thank you for your suggestions.
You are right, setting the mimetype is a must. Not setting it, KHTMLPart script thinks it's a html document and runs the script again, because it's a new KHTMLPart, generating the loop. I want to embed multimedia files only, and setting the mimetype solves the problem.
Thank you Gérard. |
![]() Registered Member ![]()
|
Sebaro, I just noticed your reply. I'm glad it worked out for you. regards, Gérard |
Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot]