View Full Version : Cancel image loading

skool h8r
12-07-2004, 07:38 PM
hi all,
I need a javascript(MUST be javascript) that can prevent an image from loading on a page but not actually preventing the rest of the page from loading.Just kind of noticing that an image from a certain URL is attempting to load and blocking it before it can continue to load.It can be as long as you like but must be able to be compiled into one single line instead of multiple lines so no 'body onload' scripts unless there are no other parts to the script so it can't have some of the script information in the head of a document and some in the body, i need something that would just fit into the body or just the head section but all on one line if that makes any sense.
kindest regards,
skool h8r.

12-07-2004, 07:41 PM
I think it's unlikely you'll be able to do that "in one line", as you requested.

The javascript that is used in events on other elements simply calls a function defined elsewhere on the page (usually in the head), and it's that function that actually tells the browser what to do.

Willy Duitt
12-07-2004, 07:53 PM
Your question was answered here (http://www.webdeveloper.com/forum/showthread.php?s=&threadid=50770)....

skool h8r
12-07-2004, 10:33 PM
Thanks for the reply but that's the thing, hosts files can't be included because it's to be included in a browsers internal workings.I read something about 'body.onload', maybe something could be done with that.maybe something like this:

body.onload("http://www.imageurl.com/imageadvert.jpg") image.stopload;

Hope that explains it a little better.I really need this as soon as possible but if someone makes one that works then their name will be included in the browsers credits and can become my first beta tester if they like.I'll tell you more about the browser another time though.If it just can't be done then it's ok, no problem, just means less advert blockin' capabilities.

12-08-2004, 02:27 AM
why not have regular expressions parse out what you don't want? that's how proxomitron (http://proxomitron.info/) worked, or of course you could use getElementsByTagName (http://www.mozilla.org/docs/dom/domref/dom_doc_ref50.html) then cycle through and do a regex match on that.. or see how Adblock (http://adblock.mozdev.org/) does it.

skool h8r
12-08-2004, 05:51 PM
hmmm, good idea actually. If i add *imageurlterm* to it, that may work, hope it does.Thanks for that, i'll give it a try. :thumbsup: