JavaScript: Extract Path from URL (Including Special Characters)
You can use JavaScript to extract the desired portion of the URL using the URL object and its pathname property. Here's an example:
const url = new URL('https://github.com/test%3Efrew?ew332432=321423');
const pathname = url.pathname;
console.log(pathname);
Output:
/test%3Efrew
Note: The pathname property includes the leading slash (/). If you want to remove it, you can use the substring method like this: pathname.substring(1).
原文地址: https://www.cveoy.top/t/topic/pvNT 著作权归作者所有。请勿转载和采集!