[wdf-dom] script elements

Alex Russell alex at netWindows.org
Wed Feb 19 20:01:38 GMT 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

(context for the kfm-devel list: a web developer wants to dynamically create 
a <script> element via DOM operations and have the script specified in the 
src attribute sourced when the attribute is assigned)

On Wednesday 19 February 2003 01:31 pm, david currey wrote:
> On Tuesday, February 18, 2003, at 04:30  PM, Alex Russell wrote:
> >  my best guess is that you'll want to set the src attribute directly,
> > like:
> >
> > 	node.src = "foo.js"; // or something similar.
>
> well i tried that, but it still didn't run. what i mean is as far as
> the dom tree is concerned safari has in fact loaded it, just doesn't
> execute any code or make any variables available.

after a bit of creative grepping, I believe that I've found the problem. The 
class defining the script element (HTMLScriptElementImpl) does not contain 
a parseAttribute() method to over-ride that of the base class. The 
analogous class to define images has the following code to handle the src 
attribute:

void HTMLImageElementImpl::parseAttribute(AttributeImpl *attr)
{
	switch (attr->id())
	{
	...
	case ATTR_SRC:
		setChanged();
		break;
	...

This works for the src attribute on images because it has the effect of 
marking the node (and it's parents) as changed, so that the next time 
DocumentImpl::updateDocumentsRendering() is swept through, the source 
attribute is checked (in RenderImage::updateFromElement in 
rendering/render_image.cpp).

Unfortunately, there's no such hook provided in the HTMLScriptElementImpl 
class to correctly handle a src attribute (re)set via DOM operations, and 
I'm still too ignorant of KHTML and KJS internals to be able to suggest a 
patch to remedy the situation (although I can guess at the first steps). So 
unless I hear otherwise from the kfm folks, it looks like we're hosed on 
Konq < 3.2 and Safari WRT to adding new script elements that get sourced 
after page load time.

I'm going to look through the html parsing codepath to try to see if I can 
understand what's required to actually source a script and get it 
interpreted in the current runtime (but that's a discussion that doesn't 
belong on wdf-dom).

- -- 
Alex Russell
alex at netWindows.org
alex at SecurePipe.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+U+KioV0dQ6uSmkYRAvdBAJ9IrnLLlkDbI+osH4sepinYWOqdaACgkw8G
AY1Tux72T0YpnCF09J00xK4=
=6vV1
-----END PGP SIGNATURE-----





More information about the kfm-devel mailing list