如下代码在火狐下不能触发onload事件.有什么解决办法么?
在IE下已解决,就差FF.var link = document.createElement("LINK");
link.id = linkId;
link.type = "text/css";
link.rel = "stylesheet";
link.href = linkHref;
document.getElementsByTagName("HEAD").item(0).appendChild(link);
link.onload = function(){alert("加载成功");};

解决方案 »

  1.   

    把下面换成link试试
    var addScript=function(file,callBack) {
        var script=document.createElement("script");
        script.type="text/javascript"; script.src=file;
        document.getElementsByTagName("head")[0].appendChild(script);
        if(!+'\v1') {
            script.onreadystatechange=function() {if(/loaded|complete/.test(script.readyState))callBack();}
        } else script.onload=callBack;
    }
      

  2.   

    看错了,估计不行
    MDC说不清楚:
    The HTML and XHTML specifications define event handlers for the link element, but it is unclear how they would be used. https://developer.mozilla.org/en/HTML/Element/link
      

  3.   

    加载CSS文件, IE和FF下其实都是加载了.但是在FF下不会触发事件var css;function include_css(css_file) {
        var html_doc = document.getElementsByTagName('head')[0];
        css = document.createElement('link');
        css.setAttribute('rel', 'stylesheet');
        css.setAttribute('type', 'text/css');
        css.setAttribute('href', css_file);
        html_doc.appendChild(css);    // alert state change
        css.onreadystatechange = function () {
            if (css.readyState == 'complete') {
                alert('CSS onreadystatechange fired');
            }
        }
        css.onload = function () {
            alert('CSS onload fired');
        }
        return false;
    }
    include_css("http://www.lastidea.net/wp-content/themes/f2/print.css");而加载JS文件FF可以触发onload事件
    var js;
    function include_js(file) {
        var html_doc = document.getElementsByTagName('head')[0];
        js = document.createElement('script');
        js.setAttribute('type', 'text/javascript');
        js.setAttribute('src', file);
        html_doc.appendChild(js);    js.onreadystatechange = function () {
            if (js.readyState == 'complete') {
                alert('JS onreadystate fired');
            }
        }    js.onload = function () {
            alert('JS onload fired');
        }
        return false;
    }
    include_js("http://www.phpied.com/files/jinc/jsalert.js");