• RyanDev.com

  • How To Use jQuery To Call A Function in iFrames.

22nd March 2011

How To Use jQuery To Call A Function in iFrames.

posted in jQuery |

The jQuery .each() function is a great way to iterate over elements and even perform a function against them.  For example, if you have a web form that has multiple iFrames and you want to validate each of the forms all at once you can do the following jQuery call.     $(“iframe”).each(function(index) { try { this.contentWindow.Validate(); } catch (e) { } });1. $(”iframe”) - will select all iFrames in a given page.2. .each() - calls a function for each iFrame3. “this” inside of the each() function actually refers to the iFrame in this case.4. function(index) { try { this.contentWindow.Validate(); } catch (e) { } } - This accesses the actual page of each iFrame by calling contentWindow and then the name of the function Validate.  This means that each page that is loaded in an iFrame has its own Validate JavaScript function either directly or through an includes file.5.The call to Validate() is inside a try/catch block in the event that one of the pages may not have a Validate event.  That will throw an Exception which is not important for this example.

This entry was posted on Tuesday, March 22nd, 2011 at 8:23 am and is filed under jQuery. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

There are currently 7 responses to “How To Use jQuery To Call A Function in iFrames.”

Why not let us know what you think by adding your own comment! Your opinion is as valid as anyone elses, so come on... let us know what you think.

  1. 1 On June 1st, 2010, payday said:

    This is a superb post RyanDev.com .
    But I was wondering how do I suscribe to the RSS feed?

  2. 2 On July 25th, 2010, svetozarchernov said:

    it was very interesting to read.
    I want to quote your post in my blog. It can?
    And you et an account on Twitter?

  3. 3 On July 31st, 2010, a_stepkin said:

    it was very interesting to read ryandev.com
    I want to quote your post in my blog. It can?
    And you et an account on Twitter?

  4. 4 On August 1st, 2010, kadabr said:

    I would like to exchange links with your site ryandev.com
    Is this possible?

  5. 5 On November 4th, 2010, Removal said:

    I’ve meant to write about something like this on my blog and you gave me an idea. Thank you.

  6. 6 On November 5th, 2010, fomi said:

    Tyvm for the helpful info! I wouldn’t have found this on my own!

  7. 7 On November 21st, 2010, brett sutcliffe said:

    well written, thanks much for the information

Leave a Reply

  • Links

  • Calendar

  • February 2012
    S M T W T F S
    « Jan    
     1234
    567891011
    12131415161718
    19202122232425
    26272829