Reputation: 2137
Ok. This might have been asked several times but my problem is slightly different. I have following page tab in my facebook application:
This facebook page tab has my website embedded as iframe into it. What I want is that is to get the URL of current page inside my application.
For example, if you open above link you see facebook URL in your browser(obviously) address bar. In my iframe I just want to retrieve the URL of the parent page in which it is embedded.
I know same-origin policies in Javascript don't allow playing with cross-domain parent page's markup using javascript but I just want to retrieve the parent page URL, thats it.
Is that possible in ANY way? Any way to access the address bar URL in my PHP application?
Thanks.
Upvotes: 0
Views: 2501
Reputation: 31489
This will be a tough one, because CORS forbids to access the outside frame:
The referrer doesn't help very much either.
If you want to use the signed_request
, and want to send custom data/parameters to your app, have a look at https://developers.facebook.com/docs/appsonfacebook/pagetabs#integrating
You can then fill the app_data
parameter, and decode that in your app.
Upvotes: 0
Reputation: 96455
You probably don’t need the “actual URL”, but only the page id, I assume …? That you can get by decoding the signed_request
parameter that gets POSTed to your app on initial load into the iframe.
How to “decode” it is described here, https://developers.facebook.com/docs/facebook-login/using-login-with-games#parsingsr
If you’re using the PHP SDK, that has a method already that does this for you.
Upvotes: 2
Reputation: 92
You can use this to access it in JavaScript:
top.location.href
"top"
is better than "parent"
. Because if your iframe is itself in another iframe then parent will return that iframe's location. "top"
will return the highest location.
Upvotes: 1
Reputation: 454
Try one of these:
parent.document.location
parent.window.document.location
parent.window.location
parent.document.location.href
I'm not sure if this will work on facebook though
Upvotes: -1