我在.aspx页面的头部添加了“test.js”文件。在test.js中我添加了一个脚本“document.body.setAttribute(”onload“,”testload()“);”document.body.setAttribute在IE-7中不起作用
这是在IE-8-9,Mozilla,Chrome和加载testLoad()函数中运行良好。
但它不工作在IE-7。
如何在IE-7中从test.js文件设置“body”的属性。
我在.aspx页面的头部添加了“test.js”文件。在test.js中我添加了一个脚本“document.body.setAttribute(”onload“,”testload()“);”document.body.setAttribute在IE-7中不起作用
这是在IE-8-9,Mozilla,Chrome和加载testLoad()函数中运行良好。
但它不工作在IE-7。
如何在IE-7中从test.js文件设置“body”的属性。
IE7不支持obj.setAttribute('onload', doSomething);
。您可以使用计时器处理IE。
var myiFrame = document.createElement("iframe");
myiFrame.setAttribute("id", "myiFrame");
myiFrame.setAttribute("src", "something.aspx");
myiFrame.setAttribute("class", "myclass");
myiFrame.setAttribute("frameBorder", "0"); //For IE
myiFrame.setAttribute("hspace", "0");
//For all:
myiFrame.setAttribute("onload", "testload();");
document.getElementById("myDiv").appendChild(myiFrame);
//For IE:
if (isIE = /*@[email protected]*/false) {
setTimeout(function() { testload() }, 500);
}
这就是它。如果您还想要加载事件监听器,则IE需要修复:
function testload() {
//Add event listener for click so that
//resize myiFrame in case any changes occur in size of content when user clicks
var content = document.getElementById("myiFrame").contentWindow.document.body;
if (content.addEventListener) { //For all
content.addEventListener('click', function() {
//find the height of the internal page
var the_height = content.scrollHeight;
//change the height of the iframe
document.getElementById("myiFrame").height = the_height + 10;
}, false);
}
else if (content.attachEvent) { //For IE
cerceveIci.attachEvent('onclick', function() {
//find the height of the internal page
var the_height = cerceveIci.scrollHeight;
//change the height of the iframe
document.getElementById("kk-iframe").height = the_height + 10;
});
}
}
本发明的设置onload的方式。我从来没有见过。 – mplungjan