Accessing Parent Iframe Object

If you ever need to access your iframe object, from within that frame, there is an easy way. All the forum / QA site answers I’ve ran into all say to fetch the object by ID, but you don’t always have the luxury of that. Here is an easier way that doesn’t require any extra prep work and has fairly good browser support.

// actual iframe object
window.frameElement 
 
// jquery iframe object
$(window.frameElement)

One quick caveat for jQuery – any alterations you’ve made to that object will not work here (ex: custom data). Use the parent window’s jQuery object instead.

parent.$(window.frameElement)

After a few days of shitty implementations off the net, I thought I’d document this. I hate iframes.