简体   繁体   中英

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" 

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

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

只需使用window.location.pathname

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM