JavaScript, / jQuery determining if the URL contains a Min String
Here's what I want to happen
Anything the variable hash contains: #/projects/X
X being anything other than blank, I want to fire an alert
Fires Alerts
#/projects/X #/proje开发者_Go百科cts/X/boo/123/123/ads/asd/ads/ads
Does not fire an alert
#/projects/
Suggestions?
if (/^#\/projects\/.+/.test(window.location.hash)) {
alert("Some project");
}
You could replace the #/projects/ part, and see if there's anything left. If so, do something:
var hash = window.location.hash;
if (hash.indexOf('#/projects')!=-1) {
if (hash.replace('#/projects/','').length > 0) {
// do stuff
}
}
精彩评论