Programmatically remove <script src="/unwanted.js".. /> reference

javascript

Solution

In short, you can't. Even if there is a hack, it would heavily depend on the way browsers parse the HTML and load the scripts and hence wouldn't be compatible with all browsers.

Problem

I have partial control of a web page where by I can enter snippets of code at various places, but I cannot remove any preexisting code. There is a script reference midway through the page ``` <script src="/unwanted.js" type="text/javascript"></script> ``` but I do not want the script to load. I cannot access the `unwanted.js` file. Is there anyway I can use javascript executing above this refernce to cause the `unwanted.js` file not to load? Edit: To answer the comments asking what and why: I'm setting up a Stack Exchange site and the WMD* js file loads halfway down the page. SE will allow you to insert HTML in various parts of the page - so you can have your custom header and footer etc. I want to override the standard WMD code with my own version of it. I can get around the problem by just loading javascript after the original WMD script loads and replacing the functions with my own - but it would be nice not to have such a large chunk of JS load needlessly. *WMD = the mark down editor used here at SO, and on the SE sites.

Original source