str represents the XMLRequest returned through ajax
/*Dynamic loading css style*/
function loadStyle(str)
{
var regExp_src=/
var matchArray_src=str.match(regExp_src);
alert(matchArray_src[0]);
if(matchArray_src){
for(var i=0;i
var str_temp = matchArray_src[i].toString();
var regExp_src_temp = /
str_temp.match(regExp_src_temp);/*The reason for repeated use of matching here is that the $1 subexpression points to the current value, otherwise it will always be the last $1 value*/
var head = document. getElementsByTagName('head')[0];
/*IE*/
if(document.all){
alert("IE");
if(document.getElementsByTagName('style' )[0])
{
var sty=document.getElementsByTagName('style')[0].innerHTML;
alert(sty);
var sty = document.getElementsByTagName('style' )[0].innerHTML;
//I don’t know how to get the current style tag of IE. I can’t use getElementsByTagName. I can only adopt this strategy, create a new one and add the previous style
var styleSheet = document.createStyleSheet();
styleSheet.cssText=sty RegExp.$1;
}
else
{
var styleSheet = document.createStyleSheet();
styleSheet.cssText=" body{background:red;}
"
alert("finished");
}
}
/*FIREFOX*/
else{
var style;
if(document.getElementsByTagName('style')[0])
{
var sty=document.getElementsByTagName('style')[0].innerHTML;
alert(sty);
document.getElementsByTagName('style')[0].innerHTML=sty RegExp.$1;
}
else
style=document.createElement('style');
style.type = 'text /css';
style.innerHTML=RegExp.$1;
head.appendChild(style);
alert(RegExp.$1);
}
}
}
}
/*Dynamic loading of script with src attribute*/
function loadScript_src(str){
var regExp_src=/
var matchArray_src=str.match(regExp_src);
if(matchArray_src)
{
for(var i=0;i
var str_temp = matchArray_src [i].toString();
var regExp_src_temp = /
str_temp.match(regExp_src_temp);
var head = document.getElementsByTagName ('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = RegExp.$1;
script.defer="true";
head.appendChild(script);
alert(RegExp.$1);
}
}
}
/*Dynamic loading of innerHTML Script*/
function loadScript(str){
var regExp_function=/<script>]*>([sS]*?)</script>[s]*>/gi;
var matchArray_function=str.match(regExp_function );
if(matchArray_function){
for(var i=0;i
var regExp_function_temp=/<script>]*>([sS]*?)</script>[s]*>/gi ;
var matchArray_temp=str_temp.match(regExp_function_temp);
eval(RegExp.$1);
}
}
}