Here is what i got:
1=page containing a form
2=page containing an iframe of 1
I created an invisible textarea in a form, so it could be filled with URL of page that cointains an iframe.
Both 1 and 2 are on different domains. I got full access to both sites.
What im trying to do is to know where from was the form sent.
Not sure if im clear enough:
I already tried to append:
<script type="text/javascript">
$(document).ready(function() {
$('textarea#id_subject').append(window.parent.location.href)
});
</script>
to 1, but it didnt work. How could i achieve this, any idea?
BTW, this iframe is going to be attached to 10-100 other sites.
You can add url of parent window as GET parameter in iframe url:
This goes in parent page.
<iframe src="http://something.com/form.html?parent_url={your url goes here}">
</iframe>
It can be done both on server side or on client side. From inside of iframe you can access this value on server side (by reading GET parameter), or on client side (by reading location.href).
this iframe is going to be attached to 10-100 other sites
The Same Origin Policy is going to get in your way.
Pass the URL via some other technique. A query string in the src of the iframe is a reasonable bet.
Related
im trying to access data which is inside an iframe. There are multiple iframes on the web pages without ID tag, source of the iframe is given in html format , no external link given.
so can i switch to a particular iframe and access data inside it ??
i tried using
var ifrm = document.getElementsByTagName('iframe')[1];
var $iFrameContents = $('ifrm').contents();
$entryContent = $iFrameContents.find('div.entry-content');
but this code is NOT working. i have attached a screenshot of my coding , can anyone help me in writing a javascript/jquery to get the data in Tag inside an iframe with index 1 .
screenshot of coding
iframe.contentWindow is its internal window, and iframe.contentWindow.document is its internal document object.
But bear in mind that iframes are subject to cross-origin rules, and you won't even be able to read the URL of the iframe if it's on a different origin. You can start with a link to same-origin, but the user could navigate it elsewhere.
window.postMessage can be used to communicate between windows on different origins, if you have control of both.
I have a page that is loaded inside. The application including this page is located on another domain. So the domain of my page and the application rendering it inside an iframe are located on different domains. The page inside iframe reads the URL it is loaded from to store in the database. The page loading has a hash in the URL.It is like:
https://www.somedomain.com/organizers/list/#type=current&sort=bydate
I am reading the URL from mypage. It is located on:
https://www.someotherdomain.com/organizers/#sample
var _url = document.referrer
The above code gives me the URL but only till "https://www.somedomain.com/organizers/list/", "#type=current&sort=bydate" is missing. I need that else this code is of no use to me. Is there a way I can read the complete URL without missing any segment?
like this
var _url = window.location;
This is by design. The browser will give you the referrer which is the URL where the user came from, however the #hashmark is technically (by its original design) a sub-navigation concept within a page, thus not passed on to the next page load.
If you were on the same domain as the parent page, you could access it via the
window.parent.location.hash
however since you are from a different domain this access will likely be blocked for security reasons.
Please guide me. Is possible to read script tag src URL content using JavaScript/jQuery. Please don't suggest JSON/Ajax/iframe options.
I have tried like
<script src="http://www.test.com" id="test">
document.getElementById('test').src
but it give only src URL.
My Exact requirements is,
I have two application, each in different web server with www.siteA.com and www.siteB.com.
In Server2, I have cross origin and iframe restriction to access the application. Example: If a request is coming from server1(siteA) to server2(siteB) via Ajax or iframe, it's restricted to access the siteB page content. But If I load siteB in script tag it's loaded, but I'm not able to get the content.
So I mentioned above, don't suggest iframe and Ajax. Help me to achieve this.
The best way really is AJAX, but it does sound like CORS is an issue for you. The only other option I can think of would be to open the page in a new browser window, although I don't know what kind of user experience implications that will have on your application.
You can open a new browser window by:
function showContent(){
var url = document.getElementById("test").src;
window.open(url, "_blank");
}
Although if you take this route, you shouldn't put the url on a script tag, because the browser will download it once (via the script tag), and then a second time on the window.open.
The method on this page: http://www.ajaxf1.com/demo/ajaxupload/ uses a form w/a target of an iframe, and an action of a page that returns a JS function that targets the original page. How does this work?
So orginal->target: iframe, action: post page; then iframe gets a JS function that->targets: original.
You are not using ajax, it's actually an old trick to post a form without reloading the page.
What's being actually reloaded is the iframe, then you get the response out of it via JS.
iFrames are like page elements that you can embed into other pages. they have a browse url different from the parent page. so the url of the iframe will be your crossdomain url and since the iframe is on the same page you can access the response from the iframe refer this one http://ajaxpatterns.org/IFrame_Call
Is there any way instead of a JS hack where I can post from an iframe to another page outside the iframe?
the iframe is posting data to a 3rd party and then just responding back with a URL which is the redirection URl thus we cannot set the form target. We are PCI compliant and thus we cannot use window.parent.location = url;
What it boils down to, it seems, is this:
1. You get a text url from a 3rd party in the iframe.
2. You want to change your page's location to that url.
3. Unless you have control over that 3rd party, all you are going to get is that text url.
Now, the only way to change your page's location automatically is with window.parent.location (or window.location.)
If changing the url of the page with javascript is not PCI compliant then you're trying to do something that is not PCI complicant.
<form> accepts a target parameter, e.g. target="_parent"
In an anchor tag you can set target='_parent' this will cause the url to be loaded into the parent window.
No, the only way is by using javascript. But it's not really a hack to use window.parent.location = url;