-1

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.

Mike Flynn
  • 22,342
  • 54
  • 182
  • 341

1 Answers1

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