Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10046 (new defect)

Opened 1 year ago

Last modified 1 year ago

[PATCH] Libraries do not load when document is MIME is application/xhtml+xml in Firefox

Reported by: Daddy Cool Assigned to: madrobby
Priority: low Milestone:
Component: script.aculo.us Version:
Severity: minor Keywords: xhtml xml firefox document.write
Cc:

Description

This patch is proposed based on this forum discussion : Sitepoint forum

The problem is happening when scriptaculous is loaded and try to load the other libraries (effects.js, dragdrop.js , etc.) into the head of the document.

When you use a document that has a MIME type set to "application/xhtml+xml" along with the Firefox navigator, the command "document.write" isn't accepted and refer to this error :

Error: uncaught exception: 
[Exception... "Object cannot be created in this context"  
code: "9" 
nsresult: "0x80530009 (NS_ERROR_DOM_NOT_SUPPORTED_ERR)"  
location: "http://localhost/script/scriptaculous/scriptaculous.js Line: 26"]

The simplest solution I've found was to use a "try" first to insert the "<script.." into the head via DOM then try a document.write

Current insert :

require: function(libraryName) {
  // inserting via DOM fails in Safari 2.0, so brute force approach
  document.write('<script type="text/javascript" src="'+libraryName+'"></script>');
},

Proposed insert :

require: function(libraryName) {
	try {
		script_tag = document.createElement('script');
		script_tag.setAttribute('type','text/javascript');
		script_tag.setAttribute('src',libraryName);
		head = document.getElementsByTagName("head")[0];
		head.appendChild(script_tag);
	} catch(e) {
    	// inserting via DOM fails in Safari 2.0, so brute force approach
	    document.write('<script type="text/javascript" src="'+libraryName+'"></script>');
	}
},

I've tested this method using Firefox 2 and Internet explorer 7 (sorry to not have an old computer to test the previous versions). Couldn't try it with Safari. Cross-tested with documents declared as "text/html" and "application/xhtml+xml".

Attachments

scriptaculous_addedTryForDocumentWriteLibraryName.patch (0.9 kB) - added by Daddy Cool on 10/31/07 20:55:05.
Diif file containing the proposed change for loading libraries
head_insert.diff (0.8 kB) - added by kangax on 11/02/07 16:01:29.
a little shorter insertion

Change History

10/31/07 20:55:05 changed by Daddy Cool

  • attachment scriptaculous_addedTryForDocumentWriteLibraryName.patch added.

Diif file containing the proposed change for loading libraries

11/02/07 16:01:29 changed by kangax

  • attachment head_insert.diff added.

a little shorter insertion

11/02/07 16:02:29 changed by kangax

  • keywords changed from xhtml xml firefox document.write DOM appendChild to xhtml xml firefox document.write.
  • priority changed from normal to low.
  • severity changed from normal to minor.