提交 b85987a6 编写于 作者: K Kohsuke Kawaguchi

supporting the callback after the script is fully loaded

See http://stackoverflow.com/questions/4845762/onload-handler-for-script-tag-in-internet-explorer
上级 b9eb8c56
...@@ -2064,10 +2064,43 @@ var DragDrop = function(id, sGroup, config) { ...@@ -2064,10 +2064,43 @@ var DragDrop = function(id, sGroup, config) {
}); });
})(); })();
function loadScript(href) { /**
var s = document.createElement("script"); * Loads the script specified by the URL.
s.setAttribute("src",href); *
document.getElementsByTagName("HEAD")[0].appendChild(s); * @param href
* The URL of the script to load.
* @param callback
* If specified, this function will be invoked after the script is loaded.
* @see http://stackoverflow.com/questions/4845762/onload-handler-for-script-tag-in-internet-explorer
*/
function loadScript(href,callback) {
var head = document.getElementsByTagName("head")[0] || document.documentElement;
var script = document.createElement("script");
script.src = href;
if (callback) {
// Handle Script loading
var done = false;
// Attach handlers for all browsers
script.onload = script.onreadystatechange = function() {
if ( !done && (!this.readyState ||
this.readyState === "loaded" || this.readyState === "complete") ) {
done = true;
callback();
// Handle memory leak in IE
script.onload = script.onreadystatechange = null;
if ( head && script.parentNode ) {
head.removeChild( script );
}
}
};
}
// Use insertBefore instead of appendChild to circumvent an IE6 bug.
// This arises when a base node is used (#2709 and #4378).
head.insertBefore( script, head.firstChild );
} }
var downloadService = { var downloadService = {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册