Is there a way to determine if a page inside an iframe can be distinguished from that same child page being accessed directly from the browser? I need to do a redirect to a page if that page isnt inside an iframe. This iframe is not cross domain so I do have access to it. I would like to specifically do this on the server side but if I cant I can do it client.
Asked
Active
Viewed 39 times
-1
-
1is this what you look for http://stackoverflow.com/questions/326069/how-to-identify-if-a-webpage-is-being-loaded-inside-an-iframe-or-directly-into-t ? – knowbody Jan 27 '15 at 23:35
-
That is the answer, mark this as a duplicate. – Mike Flynn Jan 28 '15 at 04:15
1 Answers
0
Use contentWindow
property of iframe to get its location
object. Then check location.href
property:
var iframeUrl = iframe.contentWindow.location.href;

alexpods
- 47,475
- 10
- 100
- 94
-
Can I do a comparison with that and the current URL of the page? `if(iframe.contentWindow.location.href == location.href) //redirect` – Mike Flynn Jan 28 '15 at 00:13