AnyOne
AnyOne

Reputation: 931

Converting absolute path to relative

What is best way to convert absolute path to relative path by javascript or jquery ?

for example consider as below :

"http://localhost:2011/Content/Images/Product/Large/3.jpg" 

to

 "/Content/Images/Product/Large/3.jpg" 

Upvotes: 2

Views: 3809

Answers (2)

pimvdb
pimvdb

Reputation: 154818

Use the trick that <a> elements contain location properties.

$("<a href='http://localhost:2011/Content/Images/Product/Large/3.jpg'>")
  .prop("pathname");

Upvotes: 6

Naftali
Naftali

Reputation: 146302

Just use window.location.pathname

Upvotes: 1

Related Questions