簡體   English   中英

如何將 JS 注入已加載的 JS 文件中?

[英]How can I inject JS into already loaded JS file?

假設我有一個網站,我想知道我是否可以在已加載的 JS 文件中注入 Javascript。 就像我想從已經加載的 JS 中獲取 console.log 有什么辦法嗎?

您可以添加 cript 標簽或更改現有標簽的內容:

 <html> <script id="script-a"></script> <body> <div> </div> <script id="script-b"> const scriptA = document.getElementById('script-a'); scriptA.innerText = "const myLog = () => console.log('BLABLA')"; myLog(); </script> </body> </html>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM