admin管理员组文章数量:1415645
I need to parse the given urls via Javascript but I'm not able to use .split() to acplish to this.
IE:
var str = window.location.pathname;
var substr = str.split('/');
alert(substr)
If i enter this url "/" I have thoose values "myaddress,page,2"
But it doesn't work if instead of / I insert #
I need to parse the given urls via Javascript but I'm not able to use .split() to acplish to this.
IE:
var str = window.location.pathname;
var substr = str.split('/');
alert(substr)
If i enter this url "http://mydomain./myaddress/page/2/" I have thoose values "myaddress,page,2"
But it doesn't work if instead of / I insert #
Share Improve this question asked Apr 24, 2012 at 12:57 Pennywise83Pennywise83 1,7845 gold badges33 silver badges44 bronze badges 2-
2
Are you sure
location.pathname
contains a#
? Usually that is given aslocation.hash
. – Thilo Commented Apr 24, 2012 at 12:59 - possible duplicate of Grabbing hash from URL? – Felix Kling Commented Apr 24, 2012 at 13:04
4 Answers
Reset to default 4Use window.location.hash, it gives you that portion broken out.
Also, you're trying to "split" on the #
character which won't be found in window.location.pathname
, only window.location.hash
--unless you use window.location
and search the entire url.
You are looking for location.hash
. It contains the #
itself and everything that es after it.
You need to use location.hash
property
if jquery is an option, try the https://github./allmarkedup/jQuery-URL-Parser example
var url = $.url('"http://mydomain./myaddress/page/2/#lookforme');
alert(url.attr('fragment'));
本文标签: Find the quotquot character in a string with JavascriptStack Overflow
版权声明:本文标题:Find the "#" character in a string with Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745158970a2645346.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论