开发者

Method based on URL parameter

开发者 https://www.devze.com 2023-04-01 21:40 出处:网络
I have code which I would like to execute based on all the pages in the root directory of http://www.mywebsite.com/post/

I have code which I would like to execute based on all the pages in the root directory of http://www.mywebsite.com/post/

What method would I use to target the post portion of the url, that way no matter what comes after 开发者_C百科it the code executes?

my code is:

var url = document.location.href;
if (url = 'http://www.mywebsite.com/post/') {
//do something
}

I figured it out and success!

Below is the solution:

var url = document.location.href;
if (url.indexOf("post") > 0) {
//do something
}

Ultimately I would like to use this url "http://www.mywebsite.com/post/" like a wildcard. How do I this?

0

精彩评论

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

关注公众号