[Project_owners] How do I detect frames from overlay code?

Paul Roub paul at roub.net
Wed May 18 16:40:32 EDT 2005


Paul Roub wrote:
> Trying to detect whether a given page is framed or not -- this is in 
> overlay code, triggering on a dom-content-available event.  Checking 
> window.parent, window._content.parent (with or without wrappers) always 
> returns an apparent top-level page (probably the frameset page), 
> regardless of which document is passed in as the original target.
> 

Answering my own question, at least in this particular case.  The 
original-event target passed in along with the event is the framed 
document.  If that's not equal to the top-level document 
(window._content.document), we're in a frame.  Again, this is for a 
DOMContentLoaded event.

So I added:

    isFramed: function(aEvent) 

    { 

         var framed = aEvent.originalTarget && 

                 window._content && window._content.document && 

                 (window._content.document != aEvent.originalTarget); 

 

         return(framed);
   },

Yeah, I know I'm playing it very cautiously, but DOMContentLoaded gets 
called for all manner of windows.

And in my handler,

	if (this.isFramed(aEvent))
	{
		// whatever
	}

-paul


More information about the Project_owners mailing list