Ok. This might have been asked several times but my problem is slightly different. I have following page tab in my facebook application:
Facebook Page Tab
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.
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.
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.
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.
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
Related
I want to detect direct access to my page using javascript
because I want to remove a <div> ... </div> if someone directly accessed my page
I searched and I found this: how can I check if page accessed directly on stackoverflow
and I found a website doing the same thing I want is detecting if it is a direct access to the page or not but I don't know how they do it
If you mean if it's a user, check for the X-Requested-By header in the document's request.
If you mean if it's a direct URL typed in, check for the Referrer header.
So, I need to add
https://www.rapidtables.com/tools/notepad.html in my website and I need to remove the header of their website.
Is there any way?
if you do iframedoc = document.getElementById("my_iframe").contentDocument; you can do everything you can do with document. The problem is that if you dont own the page you are embedding, your edit will be blocked by your browser because of cors (https://en.wikipedia.org/wiki/Cross-origin_resource_sharing). To bypass this you need to fetch the page with your backend server and pass the file to your javascript.
I'm using a WebView to scrape an unholy mess of a website with a bizarre mix of HTTP and Javascript redirects. In my injected script, I need to get the current URL, but it seems like none of the relevant properties ever return anything other than the URL I passed to WebView.loadUrl, even after a redirect.
I've tried:
window.location
window.location.href
document.URL
document.location
document.location.href
document.documentURI
So what's going on here and how am I supposed to get the current page's URL with Javascript?
I was injecting my script in the WebViewClient.onPageStarted method to try and make it execute as soon as possible, but it appears that the window context isn't completely set up at that point. When I moved my injection code to WebViewClient.onPageFinished, it started retrieving an accurate URL from the properties I listed. It's not really an ideal solution, since my script now has to wait for the entire page to load, but I don't know of any other way to do it.
I am encouraging people to embed my website on their own using an iFrame. What I need to do is to let the Javascript on my page find out their domain. So if they embed my page on http://yahoo.com then I need to be able to fetch that address.
How to?
I tried various things such as parent.window.location, window.location etc. But all I get is the address to my page in the iFrame.
window.parent.document.location would give you the url
try this:
window.opener.document.location
or
window.parent.document.location
I have a window, with an iframe in it.
When i clicking a button, then the iframe will load (loaded from a web site).
Is it possible to retrieve the content of that iframe? How can I retrieve the content of that page?
I can view the source code by left clicking iframes View Source.
I need to store the source in a DB.
1.
var iframe = document.getElementById("ifrm");
alert(iframe.contentWindow.document.body.innerHTML );
2.alert(window.frames['ifrm'].document.body.innerHTML);
these two comments are showing "access denied" error.
Please help me.
This should work (if it's on the same domain):
document.getElementById('iframeId').contentWindow.document.body.innerHTML
Note that you need to make sure the frame has been loaded completely before you run this code. Otherwise, you will get strange exceptions.
Disclaimer: I have not tested this.
Here's the google query I used: google query
It is generally not possible to read the contents of an iframe loaded from another server, due to the same origin security policy. However, it looks like you want to store the content on the server anyway, so why not request the content from the server?