Pages

Tuesday, March 1, 2011

Accessing iframe contents using javascript

The following is a way to access the contents of an IFrame.

var ifrm = document.frames["myIFrame"].document.forms[0]

This should return the form element associated with the iframe. In most cases where the above code fails try using window.frames instead of document.frames and that would work.

On top of this if the IFrame's document is not in the same domain as the parent frame, then you may be denied access to it's contents due to security features of most browsers.

No comments:

Post a Comment