Again, what version of IE does it work / not work in? Again, what do you mean by "doesn't work"?
I don't know if you noticed, but this is a very old script. It was designed for IE5 (IE6 was released in 2001; microsoft dropped all support for IE5 in 2005. The current version is 10).
This script was written using the global event
object, which (IIRC) went out with IE8, and never existed in [most?] other browsers at all. In modern browser, the event object is instead passed as an argument to the function.
Let's try some changes:
Code:
/* original function (rewritten below):
function tile(){
if (!document.all)
return
var source=event.srcElement
if (source.tagName=="IMG")
document.body.style.backgroundImage="url("+source.src+")"
}
*/
/* use this instead */
function tile( event ){
/* this stops the event from continuing up the DOM.
because we have another listener on the body that _removes_ the bg image,
if we let the event continue up it would simply cancel out what we do here
(you probably wouldn't even see the bg image; it would look like nothing happens).
*/
event.stopPropagation();
/* this checks .target (the standard property) first, and falls back on .srcElement for old IE versions */
var source = event.target || event.srcElement;
if( source.tagName === "IMG" ){
document.body.style.backgroundImage = "url(" + source.src + ")";
}
}
You'll also need to make a minor change in how you call it, and pass in the event object as an argument:
HTML Code:
<div onclick="tile(event);">
<img src="http://example.com/image.png">
<!-- . . .
This should work in all modern browsers, and as far back as IE6, maybe IE5 (not that IE5 is remotely important anymore. I've tested in other browsers, but I don't have IE). It's still not the best way to do things, however. I think I'll look into rewriting this script for the DD library. I'll let you know what I come up with.
Bookmarks