简体   繁体   中英

Can Javascript modify the HTML stream rather than DOM tree?

I am aware that JavaScript can change the DOM tree during HTML parsing. But can it change the html stream (byte stream from network) during the parsing?

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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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