Javascript redirect within Facebook app iframe [duplicate]
Possible Duplicate:
Facebook Login and Iframe redirection
I'm trying to do a redirect via JS within an FB app in an iframe and it's busting out of the iframe.
Currently it looks like this:
windo开发者_如何学编程w.location.href = '/bla'
But this is busting out of the iframe. How do I ensure the redirect occurs, but only within the iframe?
You have to address the frame by itself. From inside the frame you use
self.location.href='/foo';
Why self
and not window
? window
is always the full window and self
is the window of frame or iframe from within the javascript is called.
Or from outside
document.getElementById('foo').location.href = '/baz';
when the frame is like this
<iframe src="foobar" id="foo" />
If that javascript is being executed on a page that is inside the iframe, it will load the new page within the iframe. I suspect that some code on the new page (probably authentication code) is then being executed and that is what is breaking out of the frame. It may not be obvious if you are using a framework that handles the auth functions for you, but something on the new page must be executing a top.location redirect.
精彩评论