"Unknown runtime error" in IE8

I create a script utility function for my project.it works well in chrome, firefox, IE10, IE9, but it throws an "Unknown runtime error" in IE8

util.addScript = function appendStyle(scriptcontetnt) {
    var st = document.createElement('script');
    st.type = "text/javascript";


    st.innerHTML = scriptcontetnt; //throw error at this point

    document.getElementsByTagName('head')[0].appendChild(st);
    return true;
};

I know using innerhtml throw errror in ie8, so I read the different streams related to this, but didn't get the right solution for this problem

+3
source share
2 answers

innerHTML might not be the best solution for a script tag, try the following:

util.addScript = function appendStyle(scriptcontetnt) {
    var st = document.createElement('script');
    st.type = "text/javascript";

    try {
      st.innerHTML = scriptcontetnt;     
    } catch(e) {
      // IE has funky script nodes
      st.text = scriptcontetnt;
    }

    document.getElementsByTagName('head')[0].appendChild(st);
    return true;
};
0
source

According to this tag Create script in IE8 you should use textinstead innerHTML in IE <9

function appendStyle(scriptcontetnt) {
   var st = document.createElement('script');
   st.type = "text/javascript";
   st.text = scriptcontetnt; //throw error at this point
   document.getElementsByTagName('head')[0].appendChild(st);
   return true;
}; 
0

All Articles