Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added fallback for IE browsers

  • Loading branch information...
commit 2cf1b31e3ac7d78fc3a3a252380b6ce5f3769456 1 parent 532c9a2
@elbart authored
Showing with 26 additions and 22 deletions.
  1. +26 −22 lib/loader.js
View
48 lib/loader.js
@@ -24,36 +24,40 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
+
var loadScriptAsync = function(url) {
var body = document.body;
var div = document.createElement('div');
div.style.display = 'none';
body.insertBefore(div, body.firstChild);
-
- var iframe = document.createElement('iframe');
- iframe.frameborder = 0;
-
+
+ var ifr = document.createElement('iframe');
+ ifr.frameborder = 0;
+
// seems like the meebo guys use this "m" tag for some magic I don't guess right now
// so I won't use it until I see a use case for that
// var m = div.appendChild(document.createElement('m'));
-
+
// use the obvious method instead
- div.appendChild(iframe);
-
- // iframe.contentWindow is accessible since we appended the iframe to the DOM
- var doc = iframe.contentWindow.document;
+ div.appendChild(ifr);
// let's write some crazy script stuff ;)
- doc.open().writeln(
- '<script type="text/javascript">' +
- 'function appendScriptTag () {' +
- 'var script = document.createElement("script");' +
- 'script.type="text/javascript";' +
- 'script.src="' + url + '";' +
- 'document.getElementsByTagName("head")[0].appendChild(script);' +
- '}' +
- '</script>' +
- '<body onload="appendScriptTag()">');
- doc.close();
-}
-
+ var content = '<script type="text/javascript">' +
+ 'function appendScriptTag () {' +
+ 'var s = document.createElement("script");' +
+ 's.type="text/javascript";' +
+ 's.src="' + url + '";' +
+ 'document.getElementsByTagName("head")[0].appendChild(s);' +
+ '}' +
+ '</script>' +
+ '<body onload="appendScriptTag()"></body>';
+ try {
+ var doc = ifr.contentWindow.document;
+ doc.open().write(content);
+ doc.close();
+ } catch (e) {
+ // fallback for IE browsers
+ ifr.src = 'javascript:d=document.open();d.write("' +
+ content.replace(/"/g,'\\"') + '");d.close();';
+ }
+};
Please sign in to comment.
Something went wrong with that request. Please try again.