Anyone happen to know this jquery thingy?

Hi I can’t seems to find this anywhere.

Basically in my iframe there is a $(“.submit”).live(“click”, function( ) event which I need to trigger this from the parent window. Is this possible?

I tried alot of methods but can’t get it to work:

$(“#iframe”)[0].contentWindow.$.fn.(“.submit”).trigger(“click”);
$(“#iframe”).contentDocument.$(‘.submit’).click()
window.frames[“userFrame”].contentWindow.$(“.submit”).trigger(“click”);

:confused:

Any help greatly appreciated.

Is the document in the iframe from the same domain as the main document?
If not, you can’t do anything with it.

Hi Scallio,

Yes it is. Its from the same exact domain. I know how to do this from iframe to parent, but not the other way round :stuck_out_tongue:

Try this:


$('.click', document.getElementById('iframe').contentDocument).click();

Not tested btw

No dice. I tried a few modified version as well all doesn’t give error…

$(‘.submit’, window.frames[‘iFrame’]).click();
$(‘.submit’, frames[‘iFrame’]).click();
$(‘.submit’, frames[‘iFrame’].contentWindow).click();
$(‘.submit’, document.getElementById(‘iFrame’).contentWindow).click();

I don’t think it’s allowed to click elements in iframes.

When I try this it works:


var oIframe = document.getElementById('iframe');
var oDoc = oIframe.contentWindow || oIframe.contentDocument;
$('.click', oDoc.document).remove();

i.e. it removes all elements with class “click” from the iframe

However, this does nothing:


var oIframe = document.getElementById('iframe');
var oDoc = oIframe.contentWindow || oIframe.contentDocument;
$('.click', oDoc.document).click();

Geez…this is weird as it can be achieve with plain javascript. This makes my code real ugly. I have to specially define a function out of jquery $( function( ) else it can’t be access from parent :frowning:

We use this to modify iframe content in the same domain, it might be worth a go (or something similar)


$('iframe').contents().find('body').click(function(){
// do stuff
});

No dice as well. :nono:



// From Parent Window
$("#saveInfo").live("click", function( ) {
        $('#iFrame').contents().find('.test').click();

});

// From iFrame Window
$(".test").click(function( ) {
        alert("d");
    });