Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 419
Mr. Flibble Avatar asked Oct 15 '09 23:10

Mr. Flibble


2 Answers

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.

like image 35
Chetan S Avatar answered Oct 05 '22 13:10

Chetan S


Please tell us exactly what you can and cannot do, and (preferably; this sounds fascinating) why.

If you can, try inserting <!-- before the script include and --> afterwards to comment it out.

Alternatively, look through the script file and see if there's any way that you could break it or nullify its effects. (this would depend entirely on the script itself; if you want more specific advice, please post more details, or preferably, the script itself.

like image 149
SLaks Avatar answered Oct 05 '22 14:10

SLaks