RobG <rg***@iinet.net.auwrote:
er******@gmail.com wrote:
[...]
Now, if anyone can tell me why the lower span of text, which attempts
to just construct an image without ever displaying it does not work
under Safari (it crashes Safari), I would be interested.
A good place to start is with valid HTML (allowing for the non-standard
attributes like ondragstart, etc.).
<URL:
http://validator.w3.org/check?uri=ht...afaritest.html
On the off chance this may have been the problem, I fixed the various
things the validator was complaining about. No luck the second span of
text still either crashes safari when one attempts to drag or does not
result in a drag depending on how I write the code.
What I am not sure about is how myImage can be made to resolve to the
same thing that document.testimg does.
Anyone have any ideas?
The page can be found at
http://ericgorr.net/safaritest.html
I know that the myImage variable is getting the image, because the
'Test' button works correctly.
And, here's the source for the page for those who don't want to use
their browser to view the source.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;
charset=ISO-8859-1">
<title>Simple JavaScript</title>
<script language="JavaScript" type="text/javascript">
var myImage = new Image();
myImage.src = "images/getfuzzy.gif";
function BodyDragHandler() {
alert('hello');
}
function BodyDragEndHandler() {
alert('goodbye');
}
function SpanDragHandler( image, text ) {
event.dataTransfer.setData( "text/plain", text );
event.dataTransfer.effectAllowed = "copy";
event.dataTransfer.setDragImage( image, 16, 15 );
event.stopPropagation();
}
function ButtonClick() {
document.buttonimg.src = myImage.src;
}
</script>
</head>
<body ondragstart="BodyDragHandler()" ondragend="BodyDragEndHandler()">
<span style="-khtml-user-drag:element; -khtml-user-select: none;"
ondragstart="SpanDragHandler( document.testimg, 'its me' )">Drag this
text. this works.</span>
<br>
<br>
<span style="-khtml-user-drag:element; -khtml-user-select: none;"
ondragstart="SpanDragHandler( myImage, 'its me2' )">Drag this text.
either crashes or won't drag.</span>
<br>
<img name="testimg" src="images/getfuzzy.gif" alt="test picture">
<br>
<button onclick="ButtonClick();">Test</button<br>
<img name="buttonimg" src="" alt="button picture">
</body>
</html>