Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Accessing iframe dom from iframe itself

Tags:

jquery

iframe

$.fn.resizer = function(o){

    var s = {}
    $.extend(s,o);

    return this.each(function(){

        $(this).css({
            'width':s.width+20,
            'height':s.height+20
        })
            .parent().css({
                'width':s.width,
                'height':s.height
            });

    });

}

I want to do this with iframe, from inside iframe.

When i'm trying to call it from there via:

$(top).uploader_finish({
    width:original_width+<?php echo $this->sizes['width'] ?>+20,
    height:original_height+<?php echo $this->sizes['height'] ?>+80
}); 

Getting window of parent, but how to access iframe directly?

Thanks ;)

Update

The only solution i have found, is to calling like that:

$(top.document).find('iframe[name=default_1]');

And default_1 name sending like $_GET parameter inside src of iframe.

Or is there a way to get name of iframe, from inside?

Update

AHA! Found it :)

window.name

So basically it will look like this?

$(top.document).find('iframe[name='+window.name+']');
like image 277
Somebody Avatar asked Nov 14 '22 06:11

Somebody


1 Answers

you can get the frame by it's ID

document.getElementById('frameId')

or in the window.frames collection

$(document).find("iframe").attr("name");
like image 165
hunter Avatar answered Dec 14 '22 05:12

hunter