Dynamically create/Add CSS style script with regular expressions Firefox_javascript skill of IE

Source: Internet
Author: User
STR is the xmlrequest that is returned via Ajax
/* Dynamically load CSS style*/
function Loadstyle (str)
{
var regexp_src=/<style.*src\s*=\s*["'][^" ']*['].*>[^<>]*<\/style\s*>/gi;
var matcharray_src=str.match (REGEXP_SRC);
Alert (matcharray_src[0]);
if (MATCHARRAY_SRC) {
for (Var i=0;i<matcharray_src.length;i++)
{Alert ("SSS");
var str_temp = matcharray_src[i].tostring ();
var regexp_src_temp =/<style.*src\s*=\s*["'] ([^" ']* ') ["]].*>[^<>]*<\/style\s*>/gi;
Str_temp.match (regexp_src_temp);/* This is used to repeat the match so that the subexpression points to the current value, otherwise it will always be the last 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;
Do not know how to get IE current style label, with getElementsByTagName, can only take this unwise, create a new, and add the previous style
var styleSheet = Document.createstylesheet ();
stylesheet.csstext=sty+regexp.$1;
}
Else
{
var styleSheet = Document.createstylesheet ();
Stylesheet.csstext= "body{background:red;} \<br\> "
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);
}
}
}
}
/* Dynamically load script*/with SRC attribute
function Loadscript_src (str) {
var regexp_src=/<script.*src\s*=\s*["'][^" ']*['].*>[^<>]*<\/script\s*>/gi;
var matcharray_src=str.match (REGEXP_SRC);
if (MATCHARRAY_SRC)
{
for (Var i=0;i<matcharray_src.length;i++)
{
var str_temp = matcharray_src[i].tostring ();
var regexp_src_temp =/<script.*src\s*=\s*["'] ([^" ']* ') ["]].*>[^<>]*<\/script\s*>/gi;
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);
}
}
}
/* script*/in Dynamic loading innerHTML
function Loadscript (str) {
var regexp_function=/<script[^>]*> ([\s\s]*?) <\/script[\s]*>/gi;
var matcharray_function=str.match (regexp_function);
if (matcharray_function) {
for (Var i=0;i<matcharray_function.length;i++) {
var str_temp=matcharray_function[i].tostring ()//In fact, it is convenient to look backwards with regular expressions, but JavaScript is not supported, so it can only take this unwise
var regexp_function_temp=/<script[^>]*> ([\s\s]*?) <\/script[\s]*>/gi;
var matcharray_temp=str_temp.match (regexp_function_temp);
eval (regexp.$1);
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.