-1

How can I get the string after the sign #:

// get current url
var url      = window.location.href;
// output: //http://www.test.com/Tests/pagination.php?page=4#tab2
alert(url);

How can I get the name tab2 which is after #

Thanks in advance

Abu Rayane
  • 241
  • 1
  • 14

2 Answers2

2

Use this code:

window.location.hash

Return the anchor part of a URL. Assume that the current URL is http://www.example.com/test.htm#part2: #part2

The Window.location read-only property returns a Location object with information about the current location of the document.
Though Window.location is a read-only Location object, you can also assign a DOMString to it. This means that you can work with location as if it were a string in most cases: location = 'http://www.example.com' is a synonym of location.href = 'http://www.example.com'.

More Read Here

Mohamad Shiralizadeh
  • 8,329
  • 6
  • 58
  • 93
2
location.hash.replace("#","")

should do the trick

suish
  • 3,253
  • 1
  • 15
  • 34