3

When I click a link with an href=# the browser scrolls to the div instead of reloading the page. How can I force a reload?

To clarify, I do not want to just reload the page, but I want to reload the page AND go to the associated div designated with the #X. For example <a href=#153> should reload the page and go to that div.

All current questions in this regards talk about simply reloading the page; not reloading and redirecting to the div.

Yes, I am quite aware this is easily done with JavaScript. But with a task so simply, I'm sure there is a way of doing this without JavaScript.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
DGDD
  • 1,370
  • 7
  • 19
  • 36

4 Answers4

6

This worked for me:

<a href="?reload=1#153">Reload</a>

I used a trick. When you use the same address then page won't reload. But when you change address simply by adding fake param "reload=1" then page will be reloaded and navigated to specified anchor.

Btw. reloading with javascript can be tricky or misleading when you want to execute php script again with reload, cos javascript reloads only contents of page but php script is not executed.

Reken411
  • 196
  • 2
  • 6
3

Add a reload..

<a href="javascript:void(0)" onclick="window.location.reload()">Reload</a>
Amir Popovich
  • 29,350
  • 9
  • 53
  • 99
2

Like this:

<a href="javascript:location.href = location.href+'#153'">Reload</a>
Amit Joki
  • 58,320
  • 7
  • 77
  • 95
0

try this, it worked for me

<a href="yourpagelink#yourhashtag" onclick="window.location.reload()">Reload Page</a>
Shuhad zaman
  • 3,156
  • 32
  • 32