开发者

How to get everything before the hash from the address bar with Javascript?

开发者 https://www.devze.com 2023-04-05 08:43 出处:网络
I know I can get the hash value directly with this bit of code: var hash = window.location.hash; But is there anyway I can get the eve开发者_开发百科rything before the hash value directly as well?

I know I can get the hash value directly with this bit of code:

var hash = window.location.hash;

But is there anyway I can get the eve开发者_开发百科rything before the hash value directly as well?

Thank you!

Edit Using the Answer bellow: I am guessing the best way is..

var pageAddress = window.location.split('#')[0];


I use:

window.location.href.replace(window.location.hash, '');


you can try to subtract the has from the location


This took me 2s to Google: http://davidwalsh.name/javascript-window-location

You want to take the href and split it on the '#', easy enough to do in JS.


This may or may not be of interest, if you don't mind jQuery (I didn't write it):

jQuery BBQ: Back Button & Query Library: http://benalman.com/projects/jquery-bbq-plugin/


Just combine the text before the hash

window.location.origin + window.location.pathname + window.location.search
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号