How can i prevent direct linking to Frames?

Posted on 2003-12-01
Last Modified: 2010-04-09
I have a frame set. But people can still access the individual frame addresses without going throught the main frameset.

For example: instead of going to and choosing 'Us' at the top, they can just go directly to

how can i prevent this?

Question by:dunkjonesy
  • 3
  • 2
LVL 15

Expert Comment

ID: 9855884
Add this to the <body> tag of all the frames to be displayed but not the page with the frameset:

<body onLoad="
var wl = top.window.location + '';
if(wl.indexOf('htm') >= 0)
window.location = ''">

With this code, if the page is accessed normally through a frameset, it will display, but if they type it into their browser URL, it redirects them to the main page with the frameset.
LVL 15

Expert Comment

ID: 9855891
Small change to make it more frames-compatible.

<body onLoad="
var wl = parent.window.location + '';
if(wl.indexOf('htm') >= 0)
parent.window.location = ''">
LVL 15

Expert Comment

ID: 9855904
If you already have some code in your <body> tag, you just need to add this to the <body> tag:

onLoad="var wl = parent.window.location + '';if(wl.indexOf('htm') >= 0) parent.window.location = ''"
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

LVL 31

Accepted Solution

GwynforWeb earned 500 total points
ID: 9856053
This works nicely, change the body tags to

<body onload="(top.location != this.location)?true:document.location=''">

Author Comment

ID: 9856152
thankyou very much people....theres probably more than one answer to this, so i just chose the first one i tried (and the one that looked the simplest)

many thanks!
LVL 31

Expert Comment

ID: 9858775
Thanks GfW

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now