+ Reply to Thread
Results 1 to 6 of 6

Thread: Clicking links on google-like map (IE7 problem)

  1. #1
    Tarzan is offline x10Hosting Member Tarzan is an unknown quantity at this point
    Join Date
    Jun 2008
    Location
    Sweden
    Posts
    65

    Clicking links on google-like map (IE7 problem)

    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

    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;
                }
            }
    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:

    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;
        }
    and finally, the MouseUp sets dragging to false and unregister the mousemove function:

    Code:
            dragok = false;
            document.onmousemove = null;
            // ... bunch of other code that sets variables according to where ithe mouse was released ... //
    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.

  2. #2
    VPmase's Avatar
    VPmase is offline x10 Elder VPmase is an unknown quantity at this point
    Join Date
    Nov 2007
    Location
    Dixon, IL, USA
    Posts
    914

    Re: Clicking links on google-like map (IE7 problem)

    Older IE's use a different var then FF, Chrome, and the newer IE's from what I've looked up.

    Add this somewhere above your functions.
    Code:
    micro = Browser.indexOf("Microsoft");
    Then change to
    Code:
    if (temp.className == "dragclass")
                {
                    // ... set dragging to true and check mouse position.
                    document.onmousemove = MouseMove;
                    if(micro)
                                    document.mousemove = MouseMoveIE;
                    return false;
                }
    MouseMoveIE will look like this:
    Code:
        if (!e) e = window.event;
        if (dragok)
        {    
        // newleft = Element left top before dragging + new mouse position - old mouse position
            var newleft = dx + e.screenX - x;
            var newtop = dy + e.screenY- y;
            d.style.left = newleft + "px";
            d.style.top  = newtop + "px";
            return false;
        }

    Of course you might have to work at the script to get it right since i haven't tested it.

  3. #3
    Tarzan is offline x10Hosting Member Tarzan is an unknown quantity at this point
    Join Date
    Jun 2008
    Location
    Sweden
    Posts
    65

    Re: Clicking links on google-like map (IE7 problem)

    So there is a difference on how to register the onmousemove?

    What is the difference between the old MouseMove function and your MouseMoveIE? They look the same to me.

    If it wasn't clear: the problem isn't that the map doesn't move in IE7, the problem is that IE7 won't follow the A links once the map has been dragged.

  4. #4
    VPmase's Avatar
    VPmase is offline x10 Elder VPmase is an unknown quantity at this point
    Join Date
    Nov 2007
    Location
    Dixon, IL, USA
    Posts
    914

    Re: Clicking links on google-like map (IE7 problem)

    IE ver:

    Code:
     var newleft = dx + e.screenX - x;
            var newtop = dy + e.screenY- y;
    Your ver:

    Code:
     var newleft = dx + e.clientX - x;
            var newtop = dy + e.clientY - y;

    IE uses e.screenX/Y
    not e.clientX/Y
    Last edited by VPmase; 09-21-2011 at 08:57 PM.

  5. #5
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,153

    Re: Clicking links on google-like map (IE7 problem)

    The drag action, though, is working properly -- except that it's getting "stuck" in the sense that the default action on links is preempted. It's probably something to do with the event propagation (bubbling) model. You might want to check this document at quirksmode to see if it answers any questions -- it starts to get pretty close to exactly on point about two-thirds of the way down.
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

  6. #6
    Tarzan is offline x10Hosting Member Tarzan is an unknown quantity at this point
    Join Date
    Jun 2008
    Location
    Sweden
    Posts
    65

    Re: Clicking links on google-like map (IE7 problem)

    I got it!
    I had registered events on both mouse down and up:
    Code:
    document.onmousedown = mouseDown;
    document.onmouseup = mouseUp;
    When the mouse fires, I checked if I was over an A link and didn't do anything if I was. But I forgot about the onmouseup, which loaded the new map parts with AJAX. Apparently in IE it fired, before the link was visited, and returning false, it didn't follow the link.
    I solved it by unregistering the mouseUp in the MouseDown function:
    Code:
    // First, a bunch of code to register event and starting dragging if we're on the drag area and didn't hit an A tag.
    
    else // The user pressed an A tag
    {
       document.onmouseup = null;
    }

+ Reply to Thread

Similar Threads

  1. Earn 1-6 dollars a day by clicking ads
    By umang4iphone52 in forum Earning Money
    Replies: 2
    Last Post: 09-10-2011, 12:04 PM
  2. Does Web 2.0 Links Still Work For Google Ranking?
    By zarisazmn in forum Earning Money
    Replies: 0
    Last Post: 08-11-2011, 07:39 AM
  3. Earn money by clicking ads
    By stunna in forum Ads & Offers
    Replies: 4
    Last Post: 03-29-2011, 08:34 AM
  4. Clicking on my domain seems not to work.
    By marioferraro7450 in forum Free Hosting
    Replies: 7
    Last Post: 08-29-2010, 02:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers