steve
steve

Reputation: 339

How can I tell if a page is being served to an iframe?

I took the src url of an iframe containing a google map, and tried to load it in my browser, but I got this response instead:

The Google Maps Embed API must be used in an iframe.

Try it for yourself: link

How does it know that the page is being loaded in a browser, rather than a frame?

Upvotes: 0

Views: 51

Answers (1)

Mattigins
Mattigins

Reputation: 1016

if (window==window.top) { /* I'm not in an iframe */ }

Very simple javascript.

Upvotes: 1

Related Questions