Solved

How can i prevent direct linking to Frames?

Posted on 2003-12-01
6
276 Views
Last Modified: 2010-04-09
Hi,
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 http://www.citizenerased.com and choosing 'Us' at the top, they can just go directly to http://www.citizenerased.com/pages/us.html

how can i prevent this?

Cheers
0
Comment
Question by:dunkjonesy
  • 3
  • 2
6 Comments
 
LVL 15

Expert Comment

by:Timbo87
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 = 'http://www.citizenerased.com'">

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.
0
 
LVL 15

Expert Comment

by:Timbo87
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 = 'http://www.citizenerased.com'">
0
 
LVL 15

Expert Comment

by:Timbo87
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 = 'http://www.citizenerased.com'"
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 31

Accepted Solution

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

<body onload="(top.location != this.location)?true:document.location='http://www.citizenerased.com'">
0
 

Author Comment

by:dunkjonesy
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!
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 9858775
Thanks GfW
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

776 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