Using $(document).append(content) will strip out all script tags from
content and attempt to evaluate them. This throws errors when the
script tag contains content other than JavaScript, even when the type
attribute of the script tag is set appropriately. Normal browser
behavior is to ignore such content and not try to evaluate it, but
append() is inconsistent with this.

I added an exception for my specific case (text/html content for use
with John's micro-templating[1]) so the script tag would not be
stripped and I found no issues when appending (IE6/7/8b2 on IETester,
Chrome, FF3/2 linux, Opera 9.51 linux.)

It would be useful for append() to follow the behavior of browsers
regarding script tags and only attempt to evaluate scripts when the
type is missing or is a recognized script mime type (text/javascript
or application/javascript.)

Here was the patch I used:

--- jquery-1.2.6.js     2008-11-02 22:15:42.000000000 -0500
+++ jquery.patch-1.2.6.js       2008-11-02 22:25:49.000000000 -0500
@@ -508,7 +508,8 @@
                                        this;

                                // execute all scripts after the elements have 
been injected
-                               if ( jQuery.nodeName( elem, "script" ) )
+                               if ( jQuery.nodeName( elem, "script" ) &&
+                                   ( !elem.type || elem.type == 
"text/javascript" || elem.type
== "application/javascript"))
                                        scripts = scripts.add( elem );
                                else {
                                        // Remove any inner scripts for later 
evaluation


[1]: http://ejohn.org/blog/javascript-micro-templating/

Best,

Zach Carter
http://zachcarter.info

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to