Hi! I'm having a kind of strange problem. It only shows up in old IE (<=7) so if you hate browser backward compatibility, stop reading here.
In a game I'm working on, I've created a map that is draggable, very much like google maps.
On this map there are cities in A tag links. All with absolute positioning. If you click on a city, you get to the page of that city.
This works even with IE7, and here comes the strange part, ONLY if you havn't dragged the map before you click on a city. I.e. open the map page, click a city, and the link is followed, but open the map, drag it, and then click on a city link and nothing happens.
I suspect that it might have something to do with returning true to follow a link, and false if you don't want to. But that should affect other browsers too, shouldn't it?
I have a MouseDown function that checks if the mouse is clicked and then
I've even tried to explicitly returned true if you pressed a "A" tag but no luck.
The MouseMove then moves the map if dragging is true:
and finally, the MouseUp sets dragging to false and unregister the mousemove function:
So to summarize, it works in firefox, new versions of IE and Chrome. Can it be something with the values returned? I've tried to return true, but it doesn't seem to do it. And the event itsn't attached to the A link anyway. Is there a way to have the A "block" the call? Well, it seems pretty intricate to me, but maybe it's easy.
I left a bunch of code out since I thought it would disturb more than help, but I can include it if you think the problem lies somewhere in there.
In a game I'm working on, I've created a map that is draggable, very much like google maps.
On this map there are cities in A tag links. All with absolute positioning. If you click on a city, you get to the page of that city.
This works even with IE7, and here comes the strange part, ONLY if you havn't dragged the map before you click on a city. I.e. open the map page, click a city, and the link is followed, but open the map, drag it, and then click on a city link and nothing happens.
I suspect that it might have something to do with returning true to follow a link, and false if you don't want to. But that should affect other browsers too, shouldn't it?
I have a MouseDown function that checks if the mouse is clicked and then
Code:
function MouseDown(e)
{
// .... event code ... //
// If the clicked element is not a city link , update a move. Else, the link will load.
if(temp.tagName != 'A')
{
if (temp.tagName != "HTML"|"BODY" && temp.className != "dragclass")
{
temp = (typeof temp.parentNode != "undefined")?temp.parentNode:temp.parentElement;
}
if (temp.className == "dragclass")
{
// ... set dragging to true and check mouse position.
document.onmousemove = MouseMove;
return false;
}
}
The MouseMove then moves the map if dragging is true:
Code:
if (!e) e = window.event;
if (dragok)
{
// newleft = Element left top before dragging + new mouse position - old mouse position
var newleft = dx + e.clientX - x;
var newtop = dy + e.clientY - y;
d.style.left = newleft + "px";
d.style.top = newtop + "px";
return false;
}
Code:
dragok = false;
document.onmousemove = null;
// ... bunch of other code that sets variables according to where ithe mouse was released ... //
I left a bunch of code out since I thought it would disturb more than help, but I can include it if you think the problem lies somewhere in there.