Ticket #92 (new defect)
wymeditor fails when javascript is served from a different domain
| Reported by: | chris_v | Owned by: | mr_lundis |
|---|---|---|---|
| Priority: | minor | Milestone: | 2.0 |
| Component: | editor | Version: | trunk |
| Keywords: | ajax, eval | Cc: |
Description (last modified by mr_lundis) (diff)
Currently, WYM editor only works when its javascript files are served from the same domain as the page embedding the <textarea>. However, especially in high-traffic setups and/or to achieve faster page loading, it may be desirable to serve media files from a different server (e.g. page is located at http://mysite.com, and media files reside on http://media.mysite.com).
Unfortunately this is not possible with WYMeditor due to the ajax call in jquery.wymeditor.js, Line 1138 (Wymeditor.prototype.load):
if(typeof XhtmlSaxListener != 'function'){
// This is the only way to get loaded functions in the global scope until jQuery.globalEval works in safari
eval(jQuery.ajax({url:this._options.basePath
+ this._options.xhtmlParser, async:false}).responseText);
In the setup described above, this._options.basePath will be something like 'http://media.mysite.com/...'. Since the Javascript security model assumes the calling script (jquery.wymeditor.js) to be part of "mysite.com" (because it is embedded in a page served from mysite.com), the ajax call will fail.
(Note: the same applies to the ajax call some lines below; Wymeditor.prototype.configureEditorUsingRawCss() ).
This problem could be avoided if -instead of loading static code through ajax calls- other options for loading scripts dynamically would be employed (like dynamically inserting script tags). One would still have to apply domain relaxiation to the iframe's html (wymiframe.html), but at least this would be possible then.