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
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
Share
Improve this question
asked Sep 16, 2017 at 14:46
ovickoovicko
2,3023 gold badges23 silver badges39 bronze badges
2
- use replace function – Eftakhar Commented Sep 16, 2017 at 14:48
- Tried to replace but nothing changed – ovicko Commented Sep 16, 2017 at 15:00
3 Answers
Reset to default 12Consider 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);
You can use replace function
str = 'http://localhost/projects/opencart/opencart230/upload/index.php?route=product/product&product_id=40'
str.replace('&','&')
You might wanna use str.replace(/&/g, '&');
to replace all instead