javascript - iframe resizing when content is smaller than default size (300x150) -


in current scenario have page loading iframe. content of iframe cannot determined beforehand therefore need dynamically adjust size using javascript. code use accomplish following:

newiframe.onload = function() {     var cw = newiframe.contentwindow;     var doc = cw.document;     var body = doc.body,         html = doc.documentelement;      var height = math.max(body.scrollheight, body.offsetheight,         html.clientheight, html.scrollheight, html.offsetheight);      var width = math.max(body.scrollwidth, body.offsetwidth,         html.clientwidth, html.scrollwidth, html.offsetwidth);      newiframe.style.width = width + "px";     newiframe.style.height = height + "px"; } 

everything works expected except when content of iframe smaller width=300 or height=150. when case (e.g. iframe contains image w:160 , h:600) computed width wrong.

by setting initial width , height of iframe 0 issue gone because values used defaults.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -