IE Switches to Compatibility Mode When Opening Links in New Tab


Xanatos
Member
Registered: 03.12.12 14:12
Timezone: UTC +1
Posts: 13

When testing my pages in Internet Explorer (Tested with IE 9 and IE 11) I have a super weird bug where the pages look totally fine when I view them normally (like if I come from google or click a link from another page), but if I open a link with target="_blank" or if I right-click and open in a new tab then for some reason the page switches quirks mode and the layout is totally broken. If I click refresh it's still broken, but if I go to the URL bar and hit enter then it works again. Any ideas why this could be happening?


Senzon
Member
Registered: 25.05.12 19:13
Timezone: UTC +3
Posts: 17

Try adding this meta tag (best if it's at the very top of the head area):

<meta http-equiv="X-UA-Compatible" content="IE=edge"> 

Also make sure there is no text or whitespace above your DOCTYPE.


Xanatos
Member
Registered: 03.12.12 14:12
Timezone: UTC +1
Posts: 13

Unfortunately I already have that meta tag, and if I didn't then wouldn't I always see compatibility mode, not just when I open in a new tab? I really don't get it. Why would it only do it in this case?


ynori7
Administrator
Registered: 24.08.11 12:16
Timezone: UTC +2
Posts: 152

Sometimes certain addons can cause issues. Maybe you have some weird addon in your IE which sometimes starts doing things when you open new tabs? Try checking your addons list and start disabling stuff you don't need.

i537.photobucket.com/albums/ff338/ynori77/archenemysig1.jpg


Xanatos
Member
Registered: 03.12.12 14:12
Timezone: UTC +1
Posts: 13

Awesome, you're right. I apparently had an addon called "PriceSparrow". No idea what it is or how it got there, but I managed to remove it by uninstalling it through the control panel.

Unfortunately it looks like this might still affect a bunch of users (as my colleague also had this addon somehow). Any idea how I could fix this issue for people who still have addons like this?


ynori7
Administrator
Registered: 24.08.11 12:16
Timezone: UTC +2
Posts: 152

Hmm, well you said that when you reload the page it worked, so maybe you could try to detect qurks mode and do that automatically. You could check for a function which should exist in the browser but doesn't (something that maybe didn't exist before IE7 for example).

Maybe something like this would work (in the page head somewhere to prevent the user from seeing the broken page first):

<script>
(function(){
    //If the browser isn't <IE8 and getElementsByClassName doesn't exist then we must be in compatibility mode
    if(navigator.userAgent.indexOf('MSIE') !== -1 && navigator.userAgent.indexOf('MSIE 8') === -1 &&
            navigator.userAgent.indexOf('MSIE 7') === -1 && document.getElementsByClassName === undefined){
        if(window.location.href.indexOf('compatFix') === -1){
            var separator = '?';
            if(window.location.href.indexOf(separator) !== -1){
                separator = '&';
            }
            //adding a param and checking for it to prevent infinite redirect chain
            window.location.href = window.location.href + separator + 'compatFix'; //redirect to yourself
        } //else we must have already tried this fix on this user and it didn't work
    }
})();
</script>

It's pretty hacky, but maybe it would work.

i537.photobucket.com/albums/ff338/ynori77/archenemysig1.jpg


Xanatos
Member
Registered: 03.12.12 14:12
Timezone: UTC +1
Posts: 13

Awesome, it actually seems to work! Thanks grin