1

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

TMB
  • 4,683
  • 4
  • 25
  • 44
Saad Awan
  • 153
  • 2
  • 3
  • 14
  • Possible duplicate: http://stackoverflow.com/a/3193193/298240 – TMB May 30 '16 at 04:34
  • 3
    Possible duplicate of [Redirect parent window from an iframe action](http://stackoverflow.com/questions/580669/redirect-parent-window-from-an-iframe-action) – TMB May 30 '16 at 04:34

1 Answers1

-1

Use: window.top.location.href

instead of: top.location.href

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

  • 1
    jquery.js:9729 Uncaught DOMException: Blocked a frame with origin "https://www.example.com" from accessing a cross-origin frame. – Alp Altunel Mar 25 '19 at 14:46
  • Do you have the rights to redirect the top frame? You can't just do this with every page. – cloned Apr 30 '22 at 08:15