Safari not retaining variable (unless onload superfluous alert)

Safari not retaining variable (unless onload superfluous alert)

Post by David Mert » Thu, 23 Aug 2007 14:18:13


I have a little script that manages some drag-and-drop in web
browsers. The general idea is that you can drag some images to
certain places, but if you try to drop them somewhere else, they float
back to their original home. Pretty straightforward, and works
perfectly in Firefox. There *is* a problem in IE, but I'm pretty sure
that's because I'll need to wrap each <img> in a <div> to overcome
IE's "simplified" image drag-and-drop.

The perplexing problem is with Safari. I haven't tried it yet, but it
might therefore apply to other KHTML based browsers (Konquorer, etc).
The heart of the code is just the below, and the symptom is weird.
Rather than return to the proper location, images float back to (0,0)
(and pile up on top of each other). I don't show the mouseUp()
function below, but the heart of it, for this purpose, is a simple:

dragObject.style.left = dragObject.init_x;
dragObject.style.top = dragObject.init_y;

Incidentally, it occurred to me that Safari might be mysteriously
refusing to set the 'init_x' and 'init_y' attributes on the dragged
image, so I tried refactoring to use a 'init_pos' object that stored
the images in a dictionary (and looked up by their 'src'). That was
less pretty code, but also produced EXACTLY the same symptom.

In trying to debug this, I scattered some 'alert()'s in the code to
see what values were set. This mysteriously fixed the problem. At
first I thought it was something about alert()'ing on the same values
I was trying to retain; after a bit of winnowing down, I find that one
simple do-nothing alert in the onload code solves the whole problem
though. Taking it out makes it broken again though.

Here's the basic code:

function makeDraggable(item){
if (!item) { return };
item.init_x = item.x
item.init_y = item.y;
item.onmousedown = function(ev){
dragObject = this;
return false;
}
}

window.onload = function(){
alert('empty'); // Keeping this make app work in Safari!
var clips = document.getElementsByTagName('img');
for(var i=0; i < clips.length; i++) {
var clip = clips[i]
if (clip.className=="clip") {
makeDraggable(clip);
}
}
dropTarget = document.getElementById('drop_target');
}

Obviously, keeping a spurious 'alert()' is no good. I wouldn't even
care if some other spurious code were a hack to fix it, as long as it
didn't bother the user (for example, a background onload delay of a
second would be acceptable if it didn't require user interaction).
Better, of course, would be for the thing simply to work correctly (as
it does in Firefox).

Thoughts?
 
 
 

1. alert in OnLoad does not work

2. Sessions not retained in Firefox/Safari

Hi

I'm using several Sessions in my app. When the user has cookies enabled in
their browser, everything works fine. But with cookies disabled, only IE
seems to remember the sessions. In Firefox and Safari, the session values
seem to be "forgotten".

I've looked around on Google but can't find any solutions to this problem.
Plus I don't know how debug with Firefox (eg. step through the code).

So, basically I have two questions:
1. Any idea why non-IE browsers are losing their sessions when cookies are
disabled?
2. How can I step through code using non-IE browsers?

Thanks
Chris

3. Drop Down Menu not retaining value in Safari

4. Retaining a Variable without RETAIN Statement

5. base.OnLoad called, OnLoad not executed

6. SP2 firewall status alert settings not retained

7. onLoad is not onLoad

8. SCAM ALERTS -- SCAM ALERTS -- SCAM ALERTS -- SCAM ALERTS -- SCAM ALERTS 2

9. SCAM ALERTS -- SCAM ALERTS -- SCAM ALERTS -- SCAM ALERTS -- SCAM ALERTS --

10. SCAM ALERTS -- SCAM ALERTS -- SCAM ALERTS -- SCAM ALERTS -- WHINE ALERTS 2

11. the xml's onload can NOT access the variable

12. midi-onload+Safari=unexpected results

13. Safari vs multiple onload events ??

14. eliminating duplicacy variables as well as retain the duplicacy variables?

15. Public variable does not retain value