How to remove script tag with javascript and load it on scroll | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to remove script tag with javascript and load it on scroll

I want to remove specific script tag that's loading inside document that contain a string after that i want to load the script that we removed on scroll. For example, myscript.js is loading inside </head> <head> <script src="/folder/code/js/myscript.js"> </head> I want to remove the script if contains string myscript.js without specifying folder. When the scroll event occurred i want to load myscript.js I know it is hard but possible. Any help will be appreciated. Thanks.

15th Mar 2020, 1:02 PM
Uzair Malim
Uzair Malim - avatar
1 Answer
- 1
You don't have to! Inside myscript.js, wrap all the contents with window.onload = function(){ //content of myscript.js goes here } That is all. But remember any function declaration should not be wrapped
15th Mar 2020, 1:10 PM
Ore
Ore - avatar