Book Sale! Code WP2025 takes 20% OFF our Pro Plugins & Books »
Web Dev + WordPress + Security

HTML Frames Notes Plus

If you think that nobody uses frames anymore, think again. I personally know of one person who threw down some tuff HTML frame action for a personal site. So, in the interest of prosperity, we are hereby establishing this post as our official dumping ground for all HTML frame-related garbage.

Break your pages out of someone else’s frames

We begin our journey with a totally sick JavaScript method for breaking pages out of the illegitimate frames of some pathetic ineffectual mouth-breather:

if (window.self ! = window.top) window.top.location = window.self.location;

Likewise, here is an equally effective method that should work in all JS-enabled browsers:

if (window.frames) {
	if (parent != self) {
		location.href="index.html"
	}
}

Alternatively, this method also works well:

if (parent.frames.length > 0) {
	parent.location.href = location.href;
}

Here is a similar version of the previous method:

if (parent.frames.length > 0) top.location.replace(document.location);

Here is yet another slightly similar version:

if (top.frames.length > 0) top.location = self.location;

Yet another fine method for breaking out of frames:

if ( top.location != document.location.href ) top.location = document.location.href;

Here is the script we use at Monzilla Media:

if ( self.location.href != top.location.href ) top.location.href = self.location.href;

This method stops recursively framed pages:

if ( window != top ) top.location.href = window.location.href;

This method works great at breaking out and redirecting the browser to the original page:

var parent_location = new String(parent.location);
if ( ( top.location != location ) && parent_location.indexOf('http://domain.tld/path/to/page.html') != 0 ) top.location.href = document.location.href;

Optimize the content of an iframe

Moving right along, here is a helpful method for optimizing the content of an <iframe>. This code basically displays a link to the content that should be displayed if everything is working correctly. If for some reason the content is not displayed, the link will appear in its place, thereby enabling users to access the missing content via a new window:

<iframe src="page.html" width="333" height="333" scrolling="auto" frameborder="1">
	<a href="page.html" target="_blank">
		[Your browser does not support frames or is configured not to display frames. Click here to visit the related document.]
	</a>
</iframe>

Control frameborder & scroll properties for iframe

To control the frameborder="value" and scroll="yes/no" attributes for iframes using CSS, add the following styles to the document which is being displayed in the iframe:

html, body {
	overflow: hidden;
	border: none;
}

See also: Break Out of Frames

About the Author
Jeff Starr = Designer. Developer. Producer. Writer. Editor. Etc.
The Tao of WordPress: Master the art of WordPress.
Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
Banhammer: Protect your WordPress site against threats.
Thoughts
Finishing up the pro version of Head Meta Data plugin, launch planned this month.
Finally finished my ultimate block list to stop AI bots :) Blocks over 100 AI bots!
After 10 years working late at night, my schedule has changed. I am now a “morning person”, starting my day at 6am or earlier.
Nice update for Wutsearch search engine launchpad. Now with 19 engines including Luxxle AI-powered search.
New version of 8G Firewall (v1.4) now available for download :)
Wishing everyone a prosperous and bright New Year!
I disabled AI in Google search results. It was making me lazy.
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.