dimanche 3 juillet 2016

Uncaught ReferenceError: var is not defined & cannot read property


I try to recover dynamycally the width and height of an iframe at the load of its integration, but I have errors.

HTML

An exemple of an iframe, that I try to recuperate width and height.

<iframe src="" scrolling="no" frameBorder="0" width="640" height="360"></iframe>

jQuery

var frameEl = window.frameElement;
var widthIframe = frameEl.width;
var heightIframe = frameEl.height;

For this code, I have.

jQuery.Deferred exception: Cannot read property 'width' of null TypeError: Cannot read property 'width' of null at HTMLDocument.

After I tried to add a ready handler, and I have.

$(function()
{
    $.extend(window, {
         frameEl: window.frameElement,
         widthIframe: frameEl.width,
         heightIframe: frameEl.height,
    });
});

jQuery.Deferred exception: heightIframe is not defined ReferenceError: heightIframe is not defined at HTMLDocument.

And

jQuery.Deferred exception: frameEl is not defined ReferenceError: frameEl is not defined at HTMLDocument.

Thank's for your help to tell me what it's wrong.


Aucun commentaire:

Enregistrer un commentaire