Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

add a trailing slash javascript url

// Add trailing slash even when a query is present.
// supported in all modern browsers
let url = new URL("a?foo=bar", "https://example.com");

if (url.pathname[url.pathname.length - 1] != "/") {
	url.pathname += "/";
}

// https://example.com/a/?foo=bar
console.log(url.toString());
 
PREVIOUS NEXT
Tagged: #add #trailing #slash #javascript #url
ADD COMMENT
Topic
Name
9+8 =