0

I am trying to a variable to a local page link so I'm trying this:

<a href="#mylink" data-toggle="tab" onclick="location.href=this.href+'?currentTab=mytab;';return false;">mylink</a>

This returns:

http://mysite.php#mylink?currentTab=myTab

Is there a way of stopping it from displaying the Hash? I just want it to show the variable.

For example:

http://mysite.php?currentTab=myTab
William Barbosa
  • 4,936
  • 2
  • 19
  • 37
Satch3000
  • 47,356
  • 86
  • 216
  • 346
  • You can build needed URL using [`URLUtils`](https://developer.mozilla.org/en-US/docs/Web/API/URLUtils)' properties. Or use `String`'s methods to manually cut hash from `href`. – hindmost Nov 19 '14 at 10:53

2 Answers2

0

Simply make the href attribute empty. This is perfectly valid and will fix your issue.

Note, however, that the little preview that appears on the bottom left corner of the browser will be misleading. Unless you have a good reason to use JavaScript, it'd be better to simply include the query string (which is hard coded anyway) to the href.

Hover over both links in the snippet below to see what I'm talking about.

<a href data-toggle="tab" onclick="window.location = location.href +'?currentTab=mytab;';return false;">Link</a>

<a href="?currentTab=mytab" data-toggle="tab">Link</a>
William Barbosa
  • 4,936
  • 2
  • 19
  • 37
0

You should not use #. You should try to understand first of all how Progressive Enhancement and Unobtrusive JavaScript work.

Please refer to this answer thanks to Quentin

Prevent href="#" link from changing the URL hash

Community
  • 1
  • 1
Al K
  • 141
  • 2
  • 11