Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Custom error page loading inside an iframe

0.00/5 (No votes)
17 May 2012 1  
Hello all,When we use Custom error pages in our website, and when we load our pages inside iframes, if an error occurs the custom error page loads

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

Hello all,

When we use Custom error pages in our website, and when we load our pages inside iframes, if an error occurs the custom error page loads inside that iframe. Sometimes it breakups the site uniformity and there are times we need to display the custom error page as it is (Not load it inside the iframe). There is an easy way to do this. By having the following javascript/jQuery code within the custom error page head section, it will check whether it's loading inside an iframe. If it's loading inside an iframe, then the custom error page will set as the top page.

    <script>

        $(function () {

            if (window != window.top) { //Checks whether the custom error page is loading inside an iframe

                window.top.location = window.location; //Set the top location to custom error page location

            }

        });

    </script>

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here