admin管理员组

文章数量:1333437

How can I get the document url and pare it with an conditional branch?

Pseudo Code:

If document url = "../products.html"
Then do this piece of code();

How can I get the document url and pare it with an conditional branch?

Pseudo Code:

If document url = "../products.html"
Then do this piece of code();
Share Improve this question asked Dec 3, 2010 at 8:51 TomkayTomkay 5,16021 gold badges65 silver badges94 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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];

本文标签: javascriptJQuery IF document urlquotproductshtmlquot Then do thisStack Overflow