I recently implemented Selectivizr on an internal company website as we need to support IE7/8. Unfortunately, our site does a lot of dynamic content loading via jQuery/AJAX.
To solve this problem, I overloaded the jQuery ready function to reload Selectivizr after it performs whatever task it was set out to. My code looks like this:
$(function () {
if ($('body.ie8, body.ie7, body.comp-view8, body.comp-view7').length > 0) {
(function () {
var original = jQuery.fn.ready;
var getSelectivizr;
jQuery.fn.ready = function () {
// Execute the original method.
original.apply(this, arguments);
clearTimeout(getSelectivizr);
getSelectivizr = setTimeout(function () {
$.getScript(selectivizr);
}, 50);
}
})();
}
});
Simple enough. However, a teammate recently discovered a bug that seems to be related. In IE8/7 any select dropdown that is dynamically loaded into the page (I'm not sure if static dropdowns are effected as well as none of these pages have them), requires two clicks to open it.
To be more specific, in IE8/7, the first click seems to "focus" on the dropdown, while the second opens it. It Compatibility View, it actually opens for a split-second and then closes. The second click opens it just fine (as long as you remain focused on the dropdown).
I had assumed it might be an issue with what Selectivizr was doing, as it wasn't really designed to work with dynamically loaded content, but after a little bit of debugging, it seems that it's the setTimeout that is causing this strange behavior.
I'm at a complete loss how to fix this without removing my Selectivizr implementation.
It is probably worth noting that the setTimeout is necessary to prevent the browser from attempting to load Selectivizr multiple times if different AJAX calls are made as this can cause serious performance issues within the browser.
Note: this question does not accurately reflect the issue stated in the title, so I updated it to provide better searching! After coming back to this problem a few weeks later, I recognized that my initial debugging had led me down the wrong path. Sorry folks, but I've provided an answer to this which I hope helps!:)