简体   繁体   English

Javascript可以修改HTML流而不是DOM树吗?

[英]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.

相关问题 使用JavaScript从HTML DOM树中剥离JavaScript - Strip JavaScript from HTML DOM Tree with JavaScript 修改/移动 DOM 中现有的 html 标记(javascript) - modify / move an existing html tag in the DOM (javascript) Javascript回显HTML而不是对其进行处理 - Javascript echoing out HTML rather than processing it jQuery 中有没有办法修改 .html() 以便添加代码而不是覆盖? - Is there a way in jQuery to modify .html() so that it adds code rather than overwriting? 在JavaScript中生成两个DOM元素(而不是两个字符串)的差异 - Generating a diff of two DOM elements (rather than two strings) in javascript 使用Javascript将HTML字符串加载到DOM树中 - Load HTML string into DOM tree with Javascript 我可以让jQuery指向XML文档而不是DOM吗? - Can I make jQuery point to an XML document rather than the DOM? 我可以将Jade配置为生成可读的良好缩进的HTML代码而不是单行流吗? - Can I configure Jade to generate readable well-indentated HTML code rather than single-line stream? 如何在JavaScript字符串中使用javascript模板而不是原始HTML? - How to use javascript templating rather than raw HTML in javascript string? firefox扩展程序可以修改HTML文档的DOM,然后另存为HTML吗? - can firefox extension modify DOM of HTML document then save as HTML?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM