admin管理员组文章数量:1384555
Lets say my URL is:
/12434/example-post
I want to check if the current URL contains something after the "/"
, in other words, I wan't to check whether or not I'm at the homepage
Is this possible with jQuery?
Lets say my URL is:
http://example./12434/example-post
I want to check if the current URL contains something after the "/"
, in other words, I wan't to check whether or not I'm at the homepage http://example.
Is this possible with jQuery?
Share Improve this question edited Feb 28, 2012 at 14:38 Alicja Kario 23k4 gold badges28 silver badges45 bronze badges asked Feb 19, 2012 at 14:47 BelohlavekBelohlavek 1673 silver badges13 bronze badges 5- Not 'with jQuery' as such, but definitely with plain JavaScript (jQuery, so far as I know doesn't make it any easier or offer methods to achieve this). – David Thomas Commented Feb 19, 2012 at 14:51
- You do not need jQuery for this, raw Javascript will do. – Tadeck Commented Feb 19, 2012 at 14:51
-
@Tadeck: You mean you don't do this?
$($(window).prop('location')).prop('pathname')
:D – user1106925 Commented Feb 19, 2012 at 14:55 -
2
@amnotiam: Excellent example, a lot easier than
location.pathname
orwindow.location.pathname
, and everything is a lot faster in jQuery than in JavaScript. I am not sure why JavaScript is still being used when you have jQuery ;) – Tadeck Commented Feb 19, 2012 at 15:00 - 2 @Tadeck: Exactyl. All teh best codez are Jquery!!!!! :D – user1106925 Commented Feb 19, 2012 at 15:04
2 Answers
Reset to default 8Check location
global object. It has pathname
property:
alert( location.pathname );
window.location.href gives the url of page. Test the code
alert(window.location.href);
Does the URL contains anything afer abc./xyz i.e. xyz here can be tested with below code;
var url= window.location.href;
if(url.split("/").length>3){
// It is not the home page. It is not xyz.. It has something after /
}
else{
// you are on the home page.
}
本文标签: javascriptCheck the content after the quotquot on a URL with jQueryStack Overflow
版权声明:本文标题:javascript - Check the content after the "" on a URL with jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744490233a2608689.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论