替换 &到&;在网址中

发布于 2024-08-19 07:56:55 字数 254 浏览 5 评论 0 原文

我的页面上有大量 XML Parsing Error: EntityRef: waiting ';' 错误,只是因为开发人员在链接中错误地使用了&符号。

我不要求他使用 & 而不是 &,而是如何在页面加载后使用 jQuery 替换它们?

编辑:啊,对了,验证器读取源代码,所以它不起作用。还有其他方法可以过滤 HTML 并清除此类愚蠢的错误吗?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

后eg是否自 2024-08-26 07:56:56

这在 Javascript 中行不通,你确实需要在服务器端解决这个问题。

根据评论,您正在使用 JSP。您可以使用 JSTL (只需删除 /WEB-INF 中的 ="http://download.java.net/maven/1/jstl/jars/jstl-1.2.jar" rel="nofollow noreferrer">jstl-1.2.jar /lib) 标签。

默认转义 HTML 实体 <>&、< code>" 和 ' 可以与 结合使用。 com/products/jsp/jstl/1.1/docs/tlddocs/c/param.html" rel="nofollow noreferrer"> 默认情况下对查询参数进行编码。

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.

人间不值得 2024-08-26 07:56:56

替换页面的文本内容绝对不会影响您的验证结果,因为验证器不执行脚本。它仍然会看到所获取文档的原始内容。

如果您仍然想出于验证以外的原因执行此操作,您可以尝试类似 此插件< /a>.

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.

油焖大侠 2024-08-26 07:56:56

jQuery 无助于解决验证错误。事实上,验证器甚至不运行 JavaScript。

jQuery will not help solving validation errors. In fact, validators don't even run JavaScript.

栖竹 2024-08-26 07:56:56

页面加载和解析后,您将无法更正解析错误。唯一正确的解决方案是在服务器端进行替换。

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.

驱逐舰岛风号 2024-08-26 07:56:56

即使您可以在 jQuery 中修复它们,到那时页面已经被处理并且仍然会抛出错误。您最好对 & 进行全局搜索并手动替换它们。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文