简体   繁体   English

是否可以在文档中已经存在的注释的内部插入第三方js脚本?

[英]Is it possible for 3rd party js scripts to be injected INSIDE of an already existing comment on the document?

I'm discussing an error my coworker received on our staging environment with a few other developers. 我正在与其他一些开发人员讨论我的同事在暂存环境中收到的一个错误。 Basically what they have deduced is this: 基本上,他们得出的结论是:

We have a <script> at the top of the <body> that is commented out: <body>的顶部有一个<script>被注释掉了:

<!-- <script src="some-file.js"></script>-->

And a third-party script is being injected into the document. 并且第三方脚本被注入文档中。 This script looks like this: 该脚本如下所示:

<!-- Begin Vendor Code -->
<script src=".."></script>
<script src=".."></script>
<!-- End Vendor Code -->

What it looks like has happened is that the vendor code has been injected after the opening comment of the <script> tag that is already commented out: 看起来已经发生了这样的情况:在已经注释掉了<script>标记的开始注释之后,注入了供应商代码:

<!--<!-- Begin Vendor Code -->
<script src=".."></script>
<script src=".."></script>
<!-- End Vendor Code --><script src="some-file.js"></script>-->

This leaves a stray --> at the end that is rendered out as live text. 最后留下一个杂散--> ,将其显示为实时文本。

I've never seen this before. 我以前从未见过。 Didn't think it was possible? 认为不可能吗? My coworker says otherwise. 我的同事说不。 What's going on here? 这里发生了什么?

Any help would be greatly appreciated. 任何帮助将不胜感激。 Thanks! 谢谢!

Edit: To be clear, I'm not looking for a solution. 编辑:明确地说,我不是在寻找解决方案。 The obvious solution is to remove the commented out <script> tag. 显而易见的解决方案是删除注释掉的<script>标记。 But I want to know if this is a real thing. 但是我想知道这是否是真的。 My argument is human error . 我的论点是人为错误

XML and DOM can access comments! XML和DOM可以访问注释! Not sure if write is possible but read is. 不确定是否可以写入,但可以读取。

See https://developer.mozilla.org/de/docs/Web/API/Node/nodeType you have to loop trough the Dom and check what type of node you find. 请参阅https://developer.mozilla.org/de/docs/Web/API/Node/nodeType,您必须遍历Dom并检查找到的节点类型。 "8" is a comment! “ 8”是评论!

Example code to list all comments on a page: http://code.stephenmorley.org/javascript/dom-nodetype-constants/ 列出页面上所有注释的示例代码: http : //code.stephenmorley.org/javascript/dom-nodetype-constants/

Another answer that might help: https://stackoverflow.com/a/16151902/22470 另一个可能有用的答案: https : //stackoverflow.com/a/16151902/22470

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM