2017-09-16 123 views

回答

3

請考慮使用不包含像&這樣的HTML實體的URL。如果由於某種原因,你不能避免他們在你的網址,請執行以下操作來分析它們:

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

+1

它的工作,非常感謝 – ovicko

+0

@ovicko如果這個答案適合你,你可能想考慮標記它作爲答案。點擊帖子左側的支票。 – Twisty

0

可以使用替換功能

str = 'http://localhost/projects/opencart/opencart230/upload/index.php?route=product/product&product_id=40' 
str.replace('&','&')