Forum: comp
Page 340
Subject: Using Anchor Name= tags


  Posted by: Guru - [330592710] Tue, Feb 27, 2007, 13:25

Background: If a segment in an HTML page is identified by a tag of the following format:
< a name="code" >text segment< /a > (with the appropriate spaces eliminated)

then the browser can be directed to jump to that text segment upon loading the page by appending "#code" at the end of the URL. For example, if we load the following URL:
http://rotoguru1.com/cgi-bin/mb/comp/324.shtml#1172117949

then when the page loads, the browser will jump to the section named "1172117949". This is how links to the last post in a thread operate in this forum.

Suppose, however, that I want to jump to a specified segment of a page that results from an executable URL, rather than a simple HTML page. For example, suppose there is a script called "goHere.pl" that generates html output, and I want that page of output to be displayed starting from the segment named "start". I can't simply code the URL as goHere.pl#start because the "#start" will be interpreted differently by the script. But, I assume there must be some way to direct the browser to display the page starting from that named spot, perhaps via a javascript command, or by appropriately coding some browser element.

Anyone have an idea how to accomplish this?
 
1blue hen
      Leader
      ID: 710321114
      Tue, Feb 27, 2007, 16:20
So you don't want to go to part of a page. You want the entire contents of the page to be something you specify? If that's the case, isn't that what you're doing in mbregis.pl?

Do you mean something else?
 
2Guru
      ID: 330592710
      Tue, Feb 27, 2007, 16:36
No, the entire page will still be displayed, but the browser will automatically scroll down to the desired section - exactly as it behaves using an "xxx.html#code" URL. I just need it to do that when the html is generated from an executed URL, such as a xxx.pl or xxx.php or xxx.cgi.

mbregis.pl is different, because it completely filters out the unwanted sections.
 
3youngroman
      ID: 3751268
      Tue, Feb 27, 2007, 17:16
what if you use this simple javascript-command at the bottom of your page?

location.hash = 'anchorname'
 
4blue hen
      Leader
      ID: 710321114
      Tue, Feb 27, 2007, 17:28
I think I see what you mean.

page.html#loc

translates differently than

page.pl#loc

Interesting. I'll ask around and see what I can find.
 
5Guru
      ID: 330592710
      Tue, Feb 27, 2007, 17:45
youngroman[3] - Bingo! That works.
 
6Guru
      ID: 330592710
      Wed, Feb 28, 2007, 10:38
Interestingly, simply appending "#loc" to the end of the query string also seems to work in Firefox and MSIE 7, but not in MSIE 6. If you append the "#loc" in MSIE 6, it just seems to be ignored - although if you then apply the javascript code in [3], the browser address bar does display the #loc at the end of the URL.
 
7Guru
      ID: 330592710
      Wed, Feb 28, 2007, 11:15
Never mind. It does seem to work OK in MSIE 6 as well.