Moving out of an IFrame

The following code snippet demonstrates the redirection from an IFrame to a webpage.

Many a times we need to redirect from within a IFrame to a webpage. We can achieve this by using javascript.

The following script checks for the location of the window to be the top and if it is not then then it redirects to be set as top. This script uses JQuery.

<script type="text/javascript">

   $(document).ready(function() {
        if (window != top)
           top.location.href = location.href;
    });

</script>

The code above is present in the JQuery window load/ready function. The JQuery ready function is the first to be executed on window load. On execution, the window is checked to be Top and if not redirected to be set as Top.

Have fun.

Tags:

One Response to “Moving out of an IFrame”

  1. Ann Says:

    Hi Julius,

    Thank you very much. this is really useful for me.

    Cheers

Leave a Reply