El tamaño de iframe automático no funciona

I had a site running on Joomla which was working perfectly before IE9. It still works perfectly but only in compatibility mode.

The problem is in the Javascript function which I used earlier to call an Iframe (this basically has 4 input forms which are loaded one after the other, different sizes) but now its showing an error. I've tried searching forums and on Google but couldn't find a solution. The error is in this line:

h = document.frames('blockrandom').document.body.scrollHeight;

generated by IE9 (error code 5002, at character 3rd). Are there any alternatives?

function iFrameHeight()  {
   var h = 0;
   if ( !document.all ) {
       h = document.getElementById('blockrandom').contentDocument.height;
       document.getElementById('blockrandom').style.height = h + 60 + 'px';
   } 
   else if ( document.all ) {
      h = document.frames('blockrandom').document.body.scrollHeight;
      document.all.blockrandom.style.height = h + 20 + 'px';
   }

}

preguntado el 28 de agosto de 11 a las 02:08

document.all so 1999 browser detection! -

1 Respuestas

There are better ways to achieve this without relying on document.frames or document.all. Echa un vistazo a esto short tutorial by Matt Cutts. After reading that, you should end up with something like the following:

var iframe = document.getElementById('blockrandom');
iframe.style.height = iframe.contentWindow.document.body.scrollHeight + 'px';

Respondido 28 ago 11, 14:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.