SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2007
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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");



    Any help greatly appreciated.

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,080
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Is the document in the iframe from the same domain as the main document?
    If not, you can't do anything with it.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2007
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,080
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Try this:

    Code:
    $('.click', document.getElementById('iframe').contentDocument).click();
    Not tested btw
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2007
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 Dunno LOL ¯\(°_o)/¯

  6. #6
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,080
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    I don't think it's allowed to click elements in iframes.

    When I try this it works:
    Code javascript:
    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:
    Code javascript:
    var oIframe = document.getElementById('iframe');
    var oDoc = oIframe.contentWindow || oIframe.contentDocument;
    $('.click', oDoc.document).click();
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  7. #7
    SitePoint Zealot
    Join Date
    Jul 2007
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    I Dunno LOL ¯\(°_o)/¯

  8. #8
    SitePoint Enthusiast ironikart's Avatar
    Join Date
    Apr 2005
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We use this to modify iframe content in the same domain, it might be worth a go (or something similar)

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

  9. #9
    SitePoint Zealot
    Join Date
    Jul 2007
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ironikart View Post
    We use this to modify iframe content in the same domain, it might be worth a go (or something similar)

    Code JavaScript:
    $('iframe').contents().find('body').click(function(){
    // do stuff
    });
    No dice as well.

    Code JavaScript:
     
    // From Parent Window
    $("#saveInfo").live("click", function( ) {
            $('#iFrame').contents().find('.test').click();
     
    });
     
    // From iFrame Window
    $(".test").click(function( ) {
            alert("d");
        });
    I Dunno LOL ¯\(°_o)/¯


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •