I have an iframe embedded inside a fan page of FB, and I want to show a fixed box (like a dialog box) at the center of the screen.
How can I do that?
UPDATE
Look at Work For Us app:
http://www.facebook.com/DiscoverIntel?ref=nf&sk=app_404596412628
When I click in the green button behind (named "Apply for this position") it always shows the "Thank you" dialog at the center of the screen.
I just got the same problem today. The solution is you just need to get scroll position of the viewport from the parent of the iframe which is Facebook URL. So, Facebook has provided JavaScript SDK for it already.
http://developers.facebook.com/docs/reference/javascript/FB.Canvas.getPageInfo/
You can use clientHeight, clientWidth , scrollTop and scrollLeft to calculate the center position.
You can't. The
iframe
fills adiv
element that'sposition
style is set torelative
. It's impossible and for good reason too. What if the center of the screen isn't over youriframe
? Facebook doesn't want you doing anything crazy and messing with the presentation of the page itself (i.e. hiding advertisements, making a fake Facebook-looking elements, etc.).But if you are looking to center an element within the
iframe
, you can do something like this:Otherwise, you will have to stick to using JavaScript's popup box functions:
alert()
,confirm()
, andprompt()
.