in reply to •Re: Simulating internal anchors
in thread Simulating internal anchors

I plead guilty to anthropomorphizing my code!

What I mean is that I want the page to load and immediately scroll to a point half-way down - as if it had been called via http with an internal anchor on the end of the URL.

My latest idea is to put some JavaScript at the bottom of the page thus:

<script language="JavaScript"> <!-- self.location.href='#ANCHOR'; //--> </script>

and use a regexp to replace "ANCHOR" with "fred".

Early indications are that this works - but - urgh! - JavaScript... A Perlier solution is still sought!

Replies are listed 'Best First'.
•Re: Re: •Re: Simulating internal anchors
by merlyn (Sage) on Dec 02, 2002 at 00:10 UTC
    My first reaction: just don't do it. Who are you to say where to scroll my browser? I hate web sites that "take over the driving" from me.

    My second reaction: you can do it, at the cost of one redirect. You had the right idea. Print an external redirect that includes an anchor on the first hit, but include a flag so you don't keep looping. On the re-fetch from the browser, generate the appropriate stuff, and put the anchor in the right place.

    But please, just don't do it.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.