Goaler444
Goaler444

Reputation: 2621

Specifying link load location using Anchors

I have a simple link which reloads the current page. This is shown below:

echo '<a href="#" id ="mybutton"></a>';

When I click on the link it takes me to the top of the page.

How can I modify it to take me back where the link is located please?

I would also like to give it an offset so the location would not be all the way at the top but there would be a little bit of padding

Upvotes: 0

Views: 57

Answers (2)

AndrewR
AndrewR

Reputation: 6748

Maybe you want to use this Javascript, which will refresh the page, just like hitting F5 or clicking the refresh button. The browser will remember the position.

<a href="javascript:location.reload()">Refresh</a>

Upvotes: 1

Cal McLean
Cal McLean

Reputation: 1438

Try giving the <a> tag a name field? Then modify the href to direct back to it - i.e.:

<a name="thisPosition" href="#thisPosition" id="mybutton">...</a>;

EDIT: To reflect the comments, here is an addendum - the 'name' field is not strictly required, most (if not all) browsers nowadays can simply identify an 'id' attribute, so the href could be modified thusly: href="#mybutton", forgoing the 'name' attribute.

Upvotes: 1

Related Questions