http://www.somewebsite.com/somepage/someotherpage#somesection
I'm trying to convert a given URL from window.location.href
to a string and extract part of it to a variable
using regex. '/(\#.*)/g'
The URLs all contain a #
and all I basically want to do is dynamically store the characters that come after the hash,
whether or not it includes the hash.
So far my attempts haven't worked:
var pageSection = window.location.href;
newSection = pageSection.match('/(\#.*)/g');
console.log(newSection);
just returns null
. My other attempts have just returned the whole URL.
Thanks in advance.