简体   繁体   中英

How can I inject JS into already loaded JS file?

Suppose I have a website and I want to know can I inject Javascript in an already loaded JS file. like I want to console.log from an already loaded JS any way to do it?

You can add a cript tag or change the contents of an existing one:

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

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