In the previous post looking at
frames I showed you how to keep your site out of frames.
Although this is often needed it can be a little heavy handed. In this post I show you how to handle exceptions.
Not all frames are bad. If they are being used by the person linking to you to display more adverts to what are now your visitors they should be jumped out of as soon as possible. If they are adding real value to your visitors experience then you can safely leave the frame in place without too much worry.
The following code will get your site out of frames unless the frame is on a site which is in a list you specify.
re= /^http:\/\/(www\.scriptsearch).*/
if (top.location != self.location) {
if (re.test(top.location) == FALSE) {
top.location.replace(self.location)
}
}
To start things going we define a variable as a regular expression which matches the start of the url we want to allow. This site will be able to wrap our site in a frame. Here I'm only using one site (I've only found one site that I want to allow to display my site in a frame) but I could use multiple sites. The variable would look something like this:
re= /^http:\/\/(www\.scriptsearch|www\.example).*/}
If you want to add more sites then you just separate them with the pipe character (|). Remember to escape the period (.) as it has special meaning in regular expressions.
After the regular expression (regexp) pattern we move on to the logic. The first if statement may look familiar, it is the exact same as in Part 1. Inside the first if statement though there is a second. Here we test whether the site matches the regexp pattern stored in re. If it doesn't then the top location is changed and our site jumps out of the frame.
This is going to be the first post in a series of three looking at what to do if someone attempts to display one of your pages in a frame on their site. This first article is going to look at how to prevent this and why you would want to. Why avoid
Tracked: Feb 25, 09:29
This is the final instalment in a three part series. In part 1 I briefly outlined how to prevent other sites displaying your web pages within frames. In part 2 I talked about how to allow exceptions for the rare situations when you want to allow sites t
Tracked: Mar 13, 07:36