var iframe = document.createElement("iframe");
iframe.src = "http://www.baidu.com";
if (iframe.attachEvent){
iframe.attachEvent("onload", function(){
alert("Local iframe is now loaded.");
});
} else {
iframe.onload = function(){
alert("Local iframe is now loaded.");
};
}
document.body.appendChild(iframe);
iframe.src = "http://www.baidu.com";
if (iframe.attachEvent){
iframe.attachEvent("onload", function(){
alert("Local iframe is now loaded.");
});
} else {
iframe.onload = function(){
alert("Local iframe is now loaded.");
};
}
document.body.appendChild(iframe);
本文介绍了一个使用JavaScript创建并加载iframe的基本示例。示例中通过document.createElement创建了一个iframe元素,并设置了其src属性为'http://www.baidu.com'。接着,根据浏览器是否支持attachEvent来决定使用哪种方式监听iframe加载完成事件,最终在加载完成后弹出提示。
155

被折叠的 条评论
为什么被折叠?



