The traditional method is to put a link on your page that allows your visitors to click and open the existing URL in the window without the frame. Code for such a link might look like the following:
target="_top" attribute causes the web browser to open the document in the
topmost window. This method has the disadvantage of requiring your visitors to actually read
your instructions and click the link.
Alternatively, you can put the following in a file called (say) "scripts.js" and load it from every page. I do this at thesitewizard.com since it allows me to maintain one copy of the script even though it is loaded by every page on the site.
The code to include the script in your web page is:
It should be placed in the <head> section of your web page.
The function breakout_of_frame() checks to see if the URL of the topmost window is the same as the URL of the current window. If it is not the same, it sets it to be that of the current window, effectively loading the URL into the top window and removing the frames.
To use the above function automatically, you will have to call the script in the "body" tag:
If you prefer to give your visitors the choice of whether to continue in a frame or to break out of it, you can put a button on your page that users can click to break out of the frame instead of using the "onload" attribute in your <body> tag. The code for the button is as follows:
Such code may be useful if the frames are actually your own, and you want to allow your visitors to have a "No Frames" version of your pages without having to bother with specifically coding for it.
Do you find this article useful? You can learn of new articles and scripts that are published on thesitewizard.com by subscribing to the RSS feed. Simply point your RSS feed reader or a browser that supports RSS feeds at https://www.thesitewizard.com/thesitewizard.xml. You can read more about how to subscribe to RSS site feeds from my RSS FAQ.
This article is copyrighted. Please do not reproduce or distribute this article in whole or part, in any form.
It will appear on your page as: