使用javascript onresize,只能运行一次。我需要它多次工作。这是我的代码:
var hh = window.outerHeight;
var ww = window.outerWidth;
document.write("<iframe src='http://www.example.com' align='left' width='" + ww + "px' height='600px' frameborder='0'></iframe>");
window.onresize = function (){
hh = window.outerHeight;
ww = window.outerWidth;
document.write("<iframe src='http://www.example.com' align='left' width='" + ww + "px' height='600px' frameborder='0'></iframe>");
}
答案 0 :(得分:1)
您每次都在创建新的iframe。最好只选择已经制作的那个。
var hh = window.outerHeight;
var ww = window.outerWidth;
document.write("<iframe src='http://www.example.com' align='left' width='" + ww + "px' height='600px' frameborder='0'></iframe>");
window.onresize = function (){
hh = window.outerHeight;
ww = window.outerWidth;
document.querySelector("iframe").setAttribute('width', ww+'px');
}