Connecting Tech Pros Worldwide Help | Site Map

follow a link ('soft')

Joris Gillis
Guest
 
Posts: n/a
#1: Jul 23 '05
Hi everyone,

I have this nasty little problem to which I can't find a solution:

Consider an anchor <a name="Top" id="Top">Top</a>

How can I follow/execute this link from within javascript? In other words, how can I mimic the action that occurs when a user has clicked a (non-existing) <a href="#Top">click me</a> link, so that the page will be shifted to the top (that's an example - not the actual goal)

The link must be followed in the 'softest' possible manner: no opening of new window or page reloads/refreshes.

something like: document.getElementById('Top').follow()

Any help is greatly appreciated.
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
"Quot capita, tot sententiae" - Terentius , Phormio 454
RobG
Guest
 
Posts: n/a
#2: Jul 23 '05

re: follow a link ('soft')


Joris Gillis wrote:[color=blue]
> Hi everyone,
>
> I have this nasty little problem to which I can't find a solution:
>
> Consider an anchor <a name="Top" id="Top">Top</a>
>
> How can I follow/execute this link from within javascript? In other
> words, how can I mimic the action that occurs when a user has clicked a
> (non-existing) <a href="#Top">click me</a> link, so that the page will
> be shifted to the top (that's an example - not the actual goal)
>
> The link must be followed in the 'softest' possible manner: no opening
> of new window or page reloads/refreshes.
>
> something like: document.getElementById('Top').follow()[/color]

The following script modifies the window.location to go to a
specified anchor. The anchor does not have to be visible, it just
has to exist.

Note that you can't simply append the new anchor to the current URL,
so the script removes any pattern matching #.* in the string of
window.location, then adds the new anchor. This is a bit simplistic,
you may need a more robust solution.

I've wrapped lines to prevent autowrapping so the onclick looks a bit
strange.


<a href="#pageFoot" name="pageTop">Normal anchor - go to foot</a>
<br>
<input type="button" value="JS function - go to foot" onclick="
window.location =
window.location.toString().replace(/\#.*/,'') + '#pageFoot';
">
<br>
<div style="position:absolute; top:2000px; border:1px solid blue;">
<input type="button" value="JS function - go to top" onclick="
window.location =
window.location.toString().replace(/\#.*/,'') + '#pageTop';
">
<br>
<a name="pageFoot" href="#pageTop">Normal anchor - to to top</a>
</div>

[color=blue]
>
> Any help is greatly appreciated.[/color]


--
Rob
Martin Honnen
Guest
 
Posts: n/a
#3: Jul 23 '05

re: follow a link ('soft')




Joris Gillis wrote:
[color=blue]
> I have this nasty little problem to which I can't find a solution:
>
> Consider an anchor <a name="Top" id="Top">Top</a>
>
> How can I follow/execute this link from within javascript?[/color]

It is an anchor not a link but you can move to an anchor with
window.location.hash = '#Top';

--

Martin Honnen
http://JavaScript.FAQTs.com/
Closed Thread


Similar JavaScript / Ajax / DHTML bytes