How To Use jQuery To Call A Function in iFrames.
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.
posted in jQuery | 4 Comments