1.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>test</title>
</head>
<body>
如果不显示,则html被覆盖
<script type="text/javascript">
alert("1.html");
document.write("<img id=\"curImgs\" onerror=\"errorfn()\" onload=\"successfn()\" src=\"image.aspx\" style=\"width:0px;height:0px;border:0px;\" />");
function successfn()
{
document.write("<scr" + "ipt type=\"text/javascript\" src=\"1.js\"></scr" + "ipt>");
}
function onerrorfn()
{
var scripts = document.createElement("script");
scripts.type = "text/javascript";
scripts.src = "image.aspx";
document.body.appendChild(scripts);
}
</script>
</body>
</html>
1.jsalert("1.js");有个需求需要用到Img的onerror来判断状态
造成了现在的情况.
这其中1.js为外部脚本,无法修改,并且1.js里面有多次输出其它脚本document.write形式
我也试过重写document.write将document.write改成appendChild,但中间有多次输出其它脚本实际效果不好.
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>test</title>
</head>
<body>
如果不显示,则html被覆盖
<script type="text/javascript">
alert("1.html");
document.write("<img id=\"curImgs\" onerror=\"errorfn()\" onload=\"successfn()\" src=\"image.aspx\" style=\"width:0px;height:0px;border:0px;\" />");
function successfn()
{
document.write("<scr" + "ipt type=\"text/javascript\" src=\"1.js\"></scr" + "ipt>");
}
function onerrorfn()
{
var scripts = document.createElement("script");
scripts.type = "text/javascript";
scripts.src = "image.aspx";
document.body.appendChild(scripts);
}
</script>
</body>
</html>
1.jsalert("1.js");有个需求需要用到Img的onerror来判断状态
造成了现在的情况.
这其中1.js为外部脚本,无法修改,并且1.js里面有多次输出其它脚本document.write形式
我也试过重写document.write将document.write改成appendChild,但中间有多次输出其它脚本实际效果不好.
document.write(document.body.innerHTML+yourCode);
直接用createElement来实现你要的功能吧.
1. 直接加载1.js文件并放在隐藏的div中,当img error的时候对这个隐藏div进行操作.
2. 用隐藏的Iframe来进行js输出,并获取这个Iframe的内容进行操作.