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

I have a main perl/CGI page studded with action buttons that pull up detail pages with local edit forms. At the top of the main page there is already a TOC with links to the various sections. I would like to return from the detail edit pages to whence I came by returning to http://path-to-bigpage?#anchorname on form submit. So far, so clear?

My question is "What is the official CGI.pm technique for getting anchor names out of a CGI query?". Yes, I know that I could stick the anchor name in as a url param - or maybe get it from an environment variable but darn it, I want to be able to get it from the url where it was put in!!!

I tried:

my $q = new CGI; my $url = $q->self_url();
This gave me everything BUT what I want! Is this an omission from CGI.pm, or does the official CGI spec. deter scripts from accessing #anchor info.???

Replies are listed 'Best First'.
Re: Get anchors from CGI?
by Abigail-II (Bishop) on Jul 04, 2002 at 16:49 UTC
    You cannot access the #anchor part. If you look at the BNF in RFC 1738, you'll see that it's not part of a URL. When a browser encounters a link of the form:
    http://www.example.com/some/path/down/here?arguments#anchor
    it will connect to www.example.com and issue a request for /some/path/down/here?arguments. In that reply, it will look for an anchor named anchor. But this is never send to the server, so the CGI does not have to bother with it.

    Abigail

Re: Get anchors from CGI?
by chromatic (Archbishop) on Jul 04, 2002 at 16:35 UTC
    According to the Mouse book, anchors (fragment identifiers) aren't sent to web servers. You might have better luck with some JavaScript that sends a history -1 event (yuck), or the REFERER environment variable. Neither are completely reliable, but the latter seems preferable (if you want to avoid double submits).
Re: Get anchors from CGI?
by dws (Chancellor) on Jul 04, 2002 at 20:23 UTC
    What is the official CGI.pm technique for getting anchor names out of a CGI query?.

    As mentioned above, the anchor name isn't sent as part of the request. You'll need to duplicate the anchor as an argument to the CGI. That is, if the anchor is #anchorname, use a query like   http://path-to-bigpage.cgi?anchor=anchorname Then, from the CGI, you can redirect to a URL that contains #anchorname.

Re: Get anchors from CGI?
by amphiplex (Monk) on Jul 04, 2002 at 16:42 UTC
    I just tried it using netcat, the anchor is not sent to the server. (I used netscape 4.78)

    ---- kurt