Prinzhorn / skrollr-menu

skrollr plugin for hash navigation
MIT License
285 stars 143 forks source link

IE7 modifications #5

Closed leslc closed 10 years ago

leslc commented 11 years ago

Thanks Alex for your contribution!

I don't know if IE7 is officially supported for this (and you probably don't want to! :).

For others who want to support IE7 browsers, here are some changes I made to skrollr-menu. I'll probably branch these changes if I have more time later.

1) For "var href = link.getAttribute('href') " - Unfortunately IE7 will return the full URL instead of the actual text inside "href". You need to use some extra flag in getAttribute.

        //Don't use the href property (link.href) because it contains the absolute url.
        var href = link.getAttribute('href');

        // ADDITION FOR IE7 - link.getAttribute('href') in IE7 returns full URL so try again with flag 2
        if (href != null && href.indexOf('#') !== 0) {
            href = link.getAttribute('href', 2);
        }

        //Check if it's a hashlink.
        if(!/^#/.test(href)) {
            return;
        }

2) Since IE7 doesn't set "e.which" or "e.button" for click events, assume every click is valid.

        // CHANGE FOR IE7 - default to 1 if e.which and e.button aren't defined
        if((e.which || e.button || 1) !== 1) {
            return;
        }

Hope this is helpful to someone.

(EDITED: removed "mousedown" solution which had too many unintended consequences)

Prinzhorn commented 11 years ago

With your getAttribute change you're intercepting external links as well and they stop working when they contain a hash, e.g. https://github.com/Prinzhorn/skrollr#resources (#resources)

leslc commented 11 years ago

Can you explain this a bit more? The current handleClick function exits if getAttribute("href") is not a hashlink (checked by the regular expression), so I thought external links aren't valid for the skrollr menu?

Prinzhorn commented 11 years ago

Your code will run for external links as well, if they have a hash.

Prinzhorn commented 11 years ago

Nevermind. I missunderstood the second parameter. I just looked at the msdn docu.

Prinzhorn commented 11 years ago

Is there a browser for which link.getAttribute('href', 2) won't work? Chrome and FF don't complain.

alexander-schranz commented 11 years ago

I did fix the IE7 Problem with var r = t.getAttribute("href"); link = window.location.href.split('#'); r = r.replace(link[0], '');

but was an older version of the skrollr-menu where i also needed to replace hasAttribute with (typeof(t.getAttribute(n)) !== 'undefined')

Prinzhorn commented 10 years ago

I'm closing this as it was only meant as a reference for other IE 7 users anyway.