How can I redirect from inside an iFrame?

Saad Awan picture Saad Awan · May 30, 2016 · Viewed 10.9k times · Source

I use website redirect page window.location.href , its working fine on all traffic also on iframe traffic.

 <script type="text/javascript">
     window.location.href="http://newUrlLocation.com";           
 </script>

But when I use top.location.href it does not redirect from inside an iframe.

<script type="text/javascript">
    top.location.href="http://newUrlLocation.com";
</script>

Any one help me please, I want to use top.location.href for all my traffic also for iframe

Answer

kshitij kunwar picture kshitij kunwar · Nov 19, 2017

Use: window.top.location.href

instead of: top.location.href

Difference between the two: window.top.location vs window.location