<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>動(dòng)態(tài)解析HTML中的Javascript</title>
<script>
var fillHTML = function (el,HTMLString) {
if (!el) return;
if (window.ActiveXObject) { //For IE
el.innerHTML = "<img style=‘display:none‘/>" + HTMLString.replace(/<script([^>]*)>/ig, ‘<script$1 defer>‘);
el.removeChild(el.firstChild)
} else { //For Mozilla,Opare
var nSibling = el.nextSibling;
var pNode = el.parentNode;
pNode.removeChild(el);
el.innerHTML = HTMLString;
pNode.insertBefore(el,nSibling)
}
}
function T()
{
var v = "aaa<script>alert(‘a(chǎn)aa‘);function A(){}<\/script>aa";
//document.getElementById("Test").innerHTML = v;
fillHTML(document.getElementById("Test"),v);
//document.getElementById("Test").innerHTML = v;
alert(document.body.outerHTML)
}
</script>
</head>
<body>
<input name="" value="aaaa" type="button" onclick="T();A();" />
<div id="Test">
</div>
</body>
</html>
聯(lián)系客服