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!
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.
Replacing the textual content of a page will have absolutely no effect on your validation results, as a validator does not execute scripts. It will still see the original content of the fetched document.
If you still want to do it for reasons other than validation, you could try something like this plugin.
jQuery will not help solving validation errors. In fact, validators don't even run JavaScript.
You will not be able to correct parse errors after the page has already been loaded and parsed. The only correct solution is to do the replacement on the server side.
Even if you could fix them in jQuery, the page is already processed by that point and the errors would still be thrown. You would be better off doing a global search for &
and manually replacing them.
精彩评论