Search code examples
jqueryjspreplacevalidationampersand

Replace & to & in URLs


I have TONS of XML Parsing Error: EntityRef: expecting ';' errors on my page only because of the incorrect use ampersands in links by the developer.

Instead of asking him to use & instead of &, how can I replace those after page load using jQuery?

Edit: Ah right, validators read the source so it won't work. Is there any other way to filter HTML and clear out silly errors like these?

Thanks!


Solution

  • This ain't going to work in Javascript, you really need to solve this at the server side.

    As per the comments, you're using JSP. You can use the JSTL (just drop jstl-1.2.jar in /WEB-INF/lib) <c:out> and <c:url> tags for this.

    The <c:out> by default escapes HTML entities <, >, &, " and '. The <c:url> can be used in combination with <c:param> which by default encodes query parameters.