Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace & to &

Tags:

javascript

Due to some Javascript actions to vars I got & instead of & in my var: So I tried this:

  url_summer = 'http://192.168.0.20/menulb.php?w=chapter&if=If_menulb&p=' + page ;
  url_summer = url_summer.replace(/&/g, '&');
  alert(url_summer) ;

And the alert gives me:

http://192.168.0.20/menulb.php?w=chapter&if=If_menulb&p=521

This is strange, the function replace doesn't want to change & to &. If I do the same to change & to + it works!

url_summer = url_summer.replace(/&/g, '+');

How cant I change & to & ?

like image 821
defacto Avatar asked Dec 07 '11 16:12

defacto


1 Answers

Decode it like this:

var str = "http://192.168.0.20/menulb.php?w=chapter&if=If_menulb&p=521";
var div = document.createElement('div');
div.innerHTML = str
var decoded = div.firstChild.nodeValue;
like image 91
Wayne Avatar answered Oct 10 '22 07:10

Wayne