0

My page is loaded into iframe, and I need to adapt the size of that iframe using javascript. I try the following:

iframe.style.overflow = 'hidden'
iframe.scrolling = 'no'
var content = iframe.contentWindow.document.getElementById('content')
var height = content.offsetHeight + 10
iframe.style.height = height + 'px'
console.log(content.offsetWidth)
var width = content.offsetWidth + 10
iframe.style.width = width + 'px'

On FireFox it works as supposed to, but IE9 ignores both scrolling and overflow attributes. The browser mode is set to IE9-Standards.

How to get rid of that scroll in iframe under IE9?

Danubian Sailor
  • 1
  • 38
  • 145
  • 223
  • I can't replicate this on IE10 (with compatibility mode with IE9 activated through Dev Tools) with this jsfiddle: http://jsfiddle.net/lechlukasz/dGEx9/3/ – Danubian Sailor Jul 25 '13 at 20:26

1 Answers1

1

Looks like the iframe is loaded, when you're doing this. You can set:

iframe.contentWindow.document.body.style.overflow = 'hidden';

If there's a literal iframe tag on the page, you can set scrolling attribute to "no", but when setting this attribute value with JS after iframe element has been created to a page, doesn't work. If you're creating the iframe dynamically, you can set setAttribute('scrolling', 'no') before appending it into a document.

Teemu
  • 22,918
  • 7
  • 53
  • 106
  • this is exactly what I'm doing. The problem is, IE9 ignores that. Same as if I set that in Dev Tools. – Danubian Sailor Jul 25 '13 at 15:43
  • No, it's not, this sets the style _within_ the `iframe`, you're trying to manipulate the `iframe` element itself. – Teemu Jul 25 '13 at 15:44
  • Works nice, as long as I can manipulate the content of iframe, in my case I can, but in general case http://stackoverflow.com/questions/4724904/how-to-change-style-of-iframe-content-cross-domain – Danubian Sailor Jul 26 '13 at 06:17
  • @ŁukaszLech Did you read the text below the code? Both tricks are working with IE, no matter if you'll load cross-domain content to `iframe`. Your question seems to be how to disable scrolling in IE, cross-domain content access won't work in any browser. – Teemu Jul 26 '13 at 06:29
  • Ah, OK, I should set scrolling="no" before I set src? This is why my jsfiddle is functioning and my production code not? – Danubian Sailor Jul 26 '13 at 06:29
  • @ŁukaszLech I doubt the order of attributes in a tag would make any difference, works for me in both orders. I was talking about dynamically created `iframe`... Actually `scrolling` attribute should be set before appending the element to the document. – Teemu Jul 26 '13 at 06:37
  • In my case, iframe is created by external CMS, with scrolling="yes", which is what I'm changing in my JavaScript. This is exactly what makes a difference. – Danubian Sailor Jul 26 '13 at 06:51