Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks --
I realize this question, however, counting on the great success with the wisdom of the PerlMonks in topics Perl I am hoping, that with mercy, this simple question/scenario can be answered.
In a short, I have a group of pages set in a frameset; if one of the pages is accessed directly outside the frameset i want it to go and grab the framset and place itself back in it. Would this be the realm of JavaScript or a few simple yet slightly more advanced line of html?
Again... considering the great wisdom of the monks I am hoping the the question can be answered, or you can point me to a forum comparable in greatness to yours.
Many Thanks.

Replies are listed 'Best First'.
Re: OT- HTML Page and Frame Question
by Joost (Canon) on May 20, 2005 at 12:30 UTC

      you could check the HTTP referer field

      But be careful. The HTTP spec makes the referer header optional, and (in violation of the spec) a number of proxy servers munge the referer to either a URL advertising the proxy, or to a string of Xs. You could lock users out by accident.

Re: OT- HTML Page and Frame Question
by dorward (Curate) on May 20, 2005 at 12:40 UTC

    You'd need JavaScript and some server side code to do this. (Well, you could duplicate the server side functionality is client side code, but that would be bad.)

    First you need to detect if the page has been loaded outside the frameset. Check top.location with a regular expression to ensure it matches http://www.example.com/ (or whatever the URL of your frameset is) with either nothing following it, or just a query string.

    If it fails the check you need to (still with JavaScript) set top.location to http://www.example.com/ but append a query string which includes a means to identify the URL of the page the user visited - the URL itself is a good choice. Make sure you URL encode it!

    Then you need to dynamically generate your frameset. Check the query string. If no URL is included, then show the default page. If there is a URL then check that it belongs to you (this protects against pishing attacks) and then set the src attribute of the <frame> to match.

    Of course this will still fail if JavaScript is not available, and you will probably annoy users who want to view a page outside your frameset, and its quite a lot of work - so you'd probably be better off just ditching the frames in favour of something less painful.

Re: OT- HTML Page and Frame Question
by tphyahoo (Vicar) on May 20, 2005 at 13:30 UTC
    You want an html forum?

    webmasterworld.com is pretty good. digitalpoint.com also has a lot of wizards. If you know german you could try www.abakus-internet-marketing.de. There's lots of other forums.

    You're right, it does pay to know your forums. Good luck.

Re: OT- HTML Page and Frame Question
by cLive ;-) (Prior) on May 21, 2005 at 06:40 UTC

    In the head of each frame, place following:

    <script language='javascript'> if (self.location.href==top.location.href) { top.location.href = '/some/cgi/script.cgi?'+self.location.href } </script>

    Then in the cgi, create the frameset and assign the correct frame url based on $ENV{QUERY_STRING}.

    Note, you may also want to check whether URL exists before doing so to avoid possible abuse, and strip any query string info from the URL of the frame.

    Something like this (untested):

    #!/usr/bin/perl use strict; use warnings; my $url = (split '?', $ENV{QUERY_STRING})[0]; my $path = $url; $path =~ s|http://domain.name|/home/username/public_html|s; -e $path or $url = 'http://domain.name/default_frame.htm'; print <<_END_; Content-type: text/html <html> <frameset cols="200,*"> <frame src="http://domain.name/menu.htm"/> <frame src="$url"/> </frameset> </html> _END_ exit(0);

    cLive ;-)

Re: OT- HTML Page and Frame Question
by thcsoft (Monk) on May 21, 2005 at 01:48 UTC
    yes, your problem lies within the realm of javascript:
    parent.frames['theFrame'].location.replace('/new_url');
    but be aware, that the operation is permitted only, if the new URL belongs to the same domain as the frameset.

    language is a virus from outer space.