JQuery html() not parsing URLs properly

Have been racking my brains for ages on this issue…

It is a Joomla site using sh404SEF. Turning sh404SEF off fixes this issue, so I assume it is a combination of sh404SEF and jQuery html().

I am using jQuery’s html() to replace the content one of one DIV by the content of another DIV. In the replacing text is a link, which contains a tilda ~ because the site is on a CPanel development domain.

When I replaced the content using jQuery’s html() the link in the new content did not work, I have a 404 not found, even though the URL in the address bar was the exact correct URL! If I actually hit return after that URL the page showed. Very strange!!

I believe it is because html() is not encoding (decoding?) the HTML entities in the URL, i.e. the tilda. It is replacing it with the html code equivalent which is %7E. I guess the browser turns this back into the tilda but sh404SEF thinks its %7E and gives an error??

Anyway, found a simple solution from http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery.

Just used the following line to decode the copying html before inserting it into the DIV.

html = decodeURIComponent(html);