最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Javascript remove Ampersand "amp;" from the url - Stack Overflow

programmeradmin4浏览0评论

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
Add a ment  | 

3 Answers 3

Reset to default 12

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);

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

发布评论

评论列表(0)

  1. 暂无评论