[英]Can Javascript modify the HTML stream rather than DOM tree?
I am aware that JavaScript can change the DOM tree during HTML parsing. 我知道JavaScript可以在HTML解析期间更改DOM树。 But can it change the html stream (byte stream from network) during the parsing?
但它可以在解析过程中更改html流(来自网络的字节流)吗?
The HTML stream is what contains the references to your JS so no, the HTML has already been at least partially processed before JS runs. HTML流包含对JS的引用,所以不,HTML已经在JS运行之前至少部分处理过了。 What you could do though is create a separate HTML page without anything in the body and then have a script which fetches the original HTML via AJAX, screws with the response, and then injects it into the DOM.
你可以做的是创建一个单独的HTML页面,在主体中没有任何东西,然后有一个脚本,通过AJAX获取原始HTML,拧紧响应,然后将其注入DOM。 This is prone to all sorts of problems but really your only path for having client-side JS muck with server-provided HTML before adding to DOM.
这容易出现各种各样的问题,但实际上你是在添加到DOM之前让客户端JS与服务器提供的HTML混淆的唯一途径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.