2

Say that my navbar has these two URLs:

<a href='/action#?action_type=test'>test</a>

and

<a href='/action#?action_type=tset'>tset</a>

My problem is, say that you're in the 'test' page, if you click on the tset page it will just change the hash params and not force a load. The reason why I'm not using onclick listeners instead is because I want to let the user be able to ctrl + click on an element if they want it in a new tab. If I use onclick listeners that feature seems to go away. How should I proceed about this?

Stupid.Fat.Cat
  • 10,755
  • 23
  • 83
  • 144

1 Answers1

0

A hash param is actually called a fragment url.

Fragment urls aren't sent to the server (see other question), instead, they are supposed to be used to link to different parts of a page (using anchors). You shouldn't reload the page when you click on one, and browsers don't expect you too.

If you need to reload when you click a hash fragment, you're doing something wrong.

Instead, try using a query parameter instead, this will automatically reload from the server, and lets the browser know what you're doing.

<a href='/action?action_type=tset'>tset</a>

HTML requires you and the browser to agree on what you're doing. You could trick it with Javascript, but then you're losing support from the browser.

Either decide if you want to use Javascript, or decide to use query strings.

Community
  • 1
  • 1
Ben Aubin
  • 5,542
  • 2
  • 34
  • 54