Busting out of an iframe using meta-refresh or javascript?

10,165

So I added the following to my redirected pages. Luckily they have nothing posted at them so can be simply redirected. Also the use of javascript is ok as it is required to get to that point in the site.

<script type="text/javascript" language="javascript">
    if (top.frames.length>0)
    setTimeout("top.location = window.location;",100);
</script>
Share:
10,165

Related videos on Youtube

Ben Lynch
Author by

Ben Lynch

Currently working as a developer at Which?. Before Which? I previously worked for MSO.net as part of the Directline Team. I was responsible for several of the Directline Holidays websites, such as www.directline-holidays.co.uk and www.directline-flights.co.uk.

Updated on April 16, 2022

Comments

  • Ben Lynch
    Ben Lynch about 2 years

    I basically have a page which shows a "processing" screen which has been flushed to the browser. Later on I need to redirect this page, currently we use meta refresh and this normally works fine.

    With a new payment system, which includes 3D secure, we potentially end up within an iframe being directed back to our site from a third party.

    I need to be able to redirect from this page, either using javascript or meta-refresh, and bust out of the iframe if it exists.

    Cheers!

    (I have done busting out of iframes before but can't find my old code and a google search was useless, thought it was the perfect time to try Stackoverflow out!)

  • Adam Tuttle
    Adam Tuttle over 15 years
    And your delay is only 1/10th of a second. Almost indistinguishable to the end-user from an instant redirect.
  • scunliffe
    scunliffe over 15 years
    You can lose the language attribute, it is deprecated.
  • Ben Lynch
    Ben Lynch over 15 years
    Thanks guys all good points. The redirect isn't really needed as you say.