How can I get the document url and compare it with an conditional branch?
Ps开发者_开发百科eudo Code:
If document url = "../products.html"
Then do this piece of code();
If you are working with loaded html, you can try
if(window.location.pathname == "products.html"){
//do something here
}
location.pathname returns the file name or path specified by the location.
In addition, You can get the file name by
var p = window.location.pathname.split("/");
var filename = p[p.length-1];
精彩评论