简体   繁体   中英

Resize event only fires once

Using the javascript onresize, only works one time. I need it to work multiple times. Here is my code:

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>");

}

You are creating a new iframe every time. It is better to just select the one that has already been made.

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');

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM