Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get the parent URL from an Iframe's content?

Tags:

html

iframe

I'm running an c# .net app in an iframe of an asp page on an older site. Accessing the Asp page's session information is somewhat difficult, so I'd like to make my .net app simply verify that it's being called from an approved page, or else immediately halt.

Is there a way for a page to find out the url of it's parent document?

like image 712
Andrew Edvalson Avatar asked Sep 22 '08 15:09

Andrew Edvalson


People also ask

Can an iframe get parent URL?

When a page is running inside of an iframe, the parent object is different than the window object. You can still access parent from within an iframe even though you can't access anything useful on it. This code will never cause an error even when crossing origins.

Can you access parent frame from inner frame?

Once id of iframe is set, you can access iframe from inner document as shown below. var iframe = parent. document. getElementById(frameElement.id);

How do I find iframe for my parents?

To find in the parent of the iFrame use: $('#parentPrice', window. parent. document).

Can iframe access browser cookies?

Only the domain which created the cookie can read its cookie. So you have to read the cookie from within the iframe and then pass it to the parent window. If you don't have access or control over the page in the iframe then there is no way to get the cookie value.


2 Answers

top.location.href

But that will only work if both pages (the iframe and the main page) are being served from the same domain.

like image 72
Dan Avatar answered Sep 21 '22 11:09

Dan


To get the URL:

Request.UrlReferrer....

To digest the query string:

NameValueCollection qs = HttpUtility.ParseQueryString(Request.UrlReferrer.Query);
like image 23
2 revs, 2 users 57% Avatar answered Sep 20 '22 11:09

2 revs, 2 users 57%