Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

IE8 doesn't parse mediaqueries when looking at www variant of a site #20

Closed
Reggino opened this Issue · 6 comments

4 participants

@Reggino

When you're on www.example.com the script thinks all the stylesheets are already parsed. All non-www domains work fine. I think the problem sits in the regular expression used on line 45 of the script.

When I replace that regular expression with this one everything works again on IE8:

/^([a-zA-Z]+?:(\/\/)?)/
@jwilsson

Same problem occurred for me. Works when replacing the regexp with the one posted by @Kingsquare

@scottjehl
Owner

hmm okay. I'll take a look, thanks so much!

@mathiasbynens mathiasbynens referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@mathiasbynens
Collaborator

Another “fix” is to use relative URLs in the HTML. In that case you can just replace sheet.href on line 37 with sheet.getAttribute('href'), which will return the non-normalized attribute value in IE8.

@scottjehl
Owner

Thanks @mathiasbynens. I'd like it to work with abs urls too though... did you happen to try the above suggestion? I haven't had a chance to test it yet.

@mathiasbynens
Collaborator

Yeah, that works.

It took some time to figure this out, so let me just write this down :) The reason the current regex fails is this:

if( !/^([a-zA-Z]+?:(\/\/)?(www\.)?)/.test( href ) 
|| href.replace( RegExp.$1, "" ).split( "/" )[0] === win.location.host ) {}

The regex basically checks if it’s an absolute URL, and if it is, it verifies it’s on the same domain as the current page.
Since the regex includes the www. however, RegExp.$1 will equal e.g. http://www., so that entire portion (including the www.) will be removed before comparing it to window.location.host. Of course, 'foo.com' != 'www.foo.com', so the if check will fail.

IE8 normalizes sheet.href so it’s the full resolved URL, while IE7 doesn’t. (Hence my previous comment.) That’s why IE7 doesn’t have the problem as long as relative URLs are used in the HTML. If absolute URLs are used, IE7 will have the same issue.

@scottjehl
Owner

I read that 6 times, and on the 6th time, it finally made sense. :)

@scottjehl scottjehl closed this in 23f4db3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.