Search code examples
javascriptjqueryinternet-explorerfancybox

Fancybox Pop Up Warning for IE 7


I am trying to create a fancybox/lightbox warning that will display when a user visit my site using IE7. I was digging around on the Fancybox website and I came across this script that will allow the fancybox to display on the page launch. The I added an IE7 if statement to the mix. So my final code was something similar to the one below:

<!--[if IE 7]>
jQuery(document).ready(function() {
$.fancybox(
    '<h2>Hi!</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam quis mi eu elit tempor facilisis id et neque</p>',
    {
            'autoDimensions'    : false,
        'width'                 : 350,
        'height'                : 'auto',
        'transitionIn'      : 'none',
        'transitionOut'     : 'none'
    }
);
});
<![endif]-->

In short it didnt work. I put the code right after my body and also just to be clear I did have all of the js files and jquery files enabled in my head. Any ideas on how I can get this to work? Is there a better solution out there for doing this?


Solution

  • <!--[if IE 7]>
    <script>
    jQuery(document).ready(function() {
    $.fancybox(
        '<h2>Hi!</h2><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam quis mi eu elit tempor facilisis id et neque</p>',
        {
                'autoDimensions'    : false,
            'width'                 : 350,
            'height'                : 'auto',
            'transitionIn'      : 'none',
            'transitionOut'     : 'none'
        }
    );
    });
    </script>
    <![endif]-->
    

    You need the <script> tag.

    You could use a browser sniffing script instead of conditional commenting...

    Something like:

    if($.browser.msie && parseInt($.browser.version) < 8){ // This would catch IE7 and below
        //fancybox script   
    }