I’m really upset. I was just visiting a competitors Web site and found out that they had links to my FAQ pages, but when you clicked on the links, their “frame” neatly wrapped my content, which made it seem like it was their content, not mine. That stinks, and I want to know if there’s a way that I can kill or prevent this from happening to my Web pages?
There is a pretty simple solution, fortunately, because the original Web designers recognized that while having multiple pages displayed as one “montage” or “frameset” offered lots of cool design features, it would also make sites susceptible to unauthorized framing with the same HTML sequence.
To create a frameset, you use a combination of <frameset> and <frame> and there are plenty of examples of how to accomplish that online and in my popular book Creating Cool Web Sites, but let’s look at the other half of the coin, what you’re asking.
The trick is to delve into JavaScript, the scripting language of Web pages. Don’t worry, though, what we’re doing isn’t that complex, and I’m sure you can handle it!
Open up one of your Web pages and all you need to do is drop in a small JavaScript snippet surrounded by <script language=”javascript”> and </script>, like this:
if (top.location != self.location) {
top.location.replace(self.location)
}
</script>
That’s all there is to it. Now when that page is included in a frames-based layout, it will automatically “bust through” all the frames and force itself to be the topmost window. Hope that helps out!
Thanks to Dori Smith of JavaScript World.com for her tip on this splendidly efficient solution.
Dave, how do I bust out of Google’s new translation feature using a link other than the one Google provides?
As you know, it seems to throw a site into an I-frame to perform it’s magic. Unfortunately, all links within that frame stay in that frame and are also translated. Best, AntG
Hi!
This snippet is very useful, but what if I want for a certain site not to be frame breaked?
I mean, I want to allow only one site to frame mine, all other should be break.
How can I do?
Thanks in avance.
Grrrrrrrrrrrrreat code! Thanks!
Thanks for the code, its great for my blog.
ravs.us
I don’t think you can “break out of frames” without some scripting support in the client’s browser.
However, you may be able to use server side includes (basically, running scripts on the machine hosting your site, rather than in the client’s browser) and HTTP_REFERRER to replace the content of the page if the referrer is the competitor’s site. (I’ve seen people do this with images on their sites, and the image that appears on the other site’s page usually has some message about “an attempt to steal bandwidth”.)
Another possibility is to simply rename the page on your site, and replace the old page with one that explains what happened. Obviously, people who bookmarked your page will need to update their bookmarks, but people seeing your file on the competitor’s site will be notified as to what’s going on as well.
Dustin, I honestly don’t know if you can break out of frames if someone has JavaScript disabled. Perhaps someone else can pop up with an answer for this?
This is great. I’ve seen this solution before. My question is: What about the three* people out there who have javascript disabled? Is there a non-java solution or are we just happy that we’re hitting 97%+* of all web users?
* I don’t have real numbers. I pulled these out of the air.