user2268083
user2268083

Reputation: 114

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

}

Upvotes: 0

Views: 374

Answers (1)

LearnMoreCoding.com
LearnMoreCoding.com

Reputation: 123

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

}

Upvotes: 1

Related Questions