28

I'm loading a page through an iframe. If the content is sitting inside an iframe I need to add a loading spinner and if not, then no need for the spinner.

Problem: How can I use jQuery to check from within the content in the iframe if it's currently sitting in an iframe or not?

(i.e. it's simple to add jQuery to the page which loads the iframe itself, but I need the jQuery code to be in the file that's loaded inside the iframe).

4

1 に答える 1

52

どうですか

if ( self !== top ) {
// you're in an iframe
}
于 2013-08-14T12:05:25.733 に答える