Break Out of Frames Using JavaScript
I thought frames went out of style a decade ago but apparently everyone feels the need to duplicate the Digg Bar. I don't trust these framed services so I choose to use a JavaScript snippet that prevents my site from being in someone else's frame.
The JavaScript
if (top.location != self.location) {
top.location = self.location;
}
Don't let your site be framed in! Use this JavaScript snippet!
The HTML5 revolution has provided us some awesome JavaScript and HTML APIs. Some are APIs we knew we've needed for years, others are cutting edge mobile and desktop helpers. Regardless of API strength or purpose, anything to help us better do our job is a...
I work with an awesome cast of developers at Mozilla, and one of them in Daniel Buchner. Daniel's shared with me an awesome strategy for detecting when nodes have been injected into a parent node without using the deprecated DOM Events API.
For the longest time, developers were frustrated by elements with overflow not being scrollable within the page of iOS Safari. For my blog it was particularly frustrating because I display my demos in sandboxed IFRAMEs on top of the article itself, so as to not affect my site's...
Morphing an element between CSS classes is another great trick the MooTools JavaScript library enables you to do. Morphing isn't the most practical use of MooTools, but it's still a trick at your disposal.
Step 1: The XHTML
The block of content that will change is...
haha, I really like this. I agree with your thoughts on frames.
I thought I’d seen that for the last time last millennium! Although I also agree with the nasty framed services – so might have to join in and add it to my site too :) Obvious, but very easy to not think of
This is the very same basic technique for preventing clickjacking. Basic, because it doesn’t work in IE, if your site is framed with security=”restricted”
As seen on The Good Parts… shouldn’t you use !== instead of != for comparisons like this one?
d.
haha!
this is first javascript that i learn when i was baby :D
David,
i agree. I saw a few articles ranting about the Digg bar when it came out and one of them had this same solution – so I added it. Works great!
Just had an idea though – what if you could recognize where the bar was coming from (like Digg) and get rid of the bar but add some little area to your page that recognizes the user and the functionality they might want. For Digg, just add a little Digg this button or whatever the Digg bar offers. Facebook, Hootsuite, a few others that I know of.
It would be similar to the WP Greet Box Plugin that gives a quick message depending on where visitors come from.
This way you lose the bar, but keep the sharing aspects and make it look like it fits your site.
-Marty
I like frames sometimes. I think the Diggbar is really useful. However frames can be over used like you say.
I use this on one of my sites. It works OK and you need just 2 lines of javascript. Personaly I hate frames. This was popular years years ago.
Wow, haven’t seen this piece of code in 8-10 years, when using frame was the norm.