Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

How can i prevent direct linking to Frames?

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
dunkjonesy
Asked:
dunkjonesy
  • 3
  • 2
1 Solution
 
Timbo87Commented:
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
 
Timbo87Commented:
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
 
Timbo87Commented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
GwynforWebCommented:
This works nicely, change the body tags to

<body onload="(top.location != this.location)?true:document.location='http://www.citizenerased.com'">
0
 
dunkjonesyAuthor Commented:
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
 
GwynforWebCommented:
Thanks GfW
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now