Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript remove Ampersand "amp;" from the url

I have this url and I want to remove the "amp;" from it. Any ideas

http://localhost/projects/opencart/opencart230/upload/index.php?route=product/product&product_id=40
like image 342
ovicko Avatar asked Sep 12 '26 13:09

ovicko


2 Answers

Consider working with URLs that do not feature HTML entities like &. If, for some reason, you cannot avoid them in your URLs, do the following to parse them:

const url = "http://localhost/projects/opencart/opencart230/upload/index.php?route=product/product&product_id=40";
const parseResult = new DOMParser().parseFromString(url, "text/html");
const parsedUrl = parseResult.documentElement.textContent;
console.log(parsedUrl);
like image 100
ideaboxer Avatar answered Sep 15 '26 04:09

ideaboxer


You can use replace function

str = 'http://localhost/projects/opencart/opencart230/upload/index.php?route=product/product&product_id=40'
str.replace('&','&')
like image 29
ShilpeshAgre Avatar answered Sep 15 '26 04:09

ShilpeshAgre