我已经在我的.aspx页面中添加了"test.js“文件(在标题部分)。
在test.js中我添加了一个脚本"document.body.setAttribute("onload","testload()");“
它在IE-8-9,Mozilla,Chrome和加载testLoad()函数中都工作得很好。
但它在IE-7中不起作用。
如何在IE-7中设置test.js文件中的body属性。
发布于 2011-09-17 14:37:45
好呀
window.onload = testload;或
window.onload = function()
{
//Some codes
}请注意,body.onload和window.onload是不同的。如果要在加载所有资源后执行事件处理程序,请使用window.onload。
发布于 2011-12-11 02:58:18
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 = /*@cc_on!@*/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;
});
}
}https://stackoverflow.com/questions/7452945
复制相似问题