[Greasemonkey] Patterns

Mark Pilgrim pilgrim at gmail.com
Wed Apr 13 00:49:23 EDT 2005


On 4/12/05, Mark Pilgrim <pilgrim at gmail.com> wrote:
> On 4/12/05, Steve Krulewitz <shooz at mm.st> wrote:
> > How about preventing your script from getting executed in iframes?  I
> > don't know a reliable way of doing this, maybe testing window.parent for
> > null?
> 
> if (window.parent.location.href != window.location.href) { alert('i am
> a frame or iframe'); }

or

if (window.top.location.href != window.location.href) { alert('i am in
a frame or iframe'); }

This is commonly used on sites to "break out of frames", in case some
third-party site is trying to display your site in a frame (and
typically put their own ads around your content).

-- 
Cheers,
-Mark


More information about the Greasemonkey mailing list