Vamsikrishna
Vamsikrishna

Reputation: 176

jQuery Cookie not working in Chrome

I am using using jQuery cookie plugin. It is working fine in Firefox. When I am opening the same page in Chrome the value is always set to undefined. I can't find what the problem is.

$(document).ready(function () {
    alert($.cookie('Brit_vidests'));
    if ($.cookie('Brit_vidests') != '1') {

        var id = '#dialog';

        var maskHeight = $(document).height();
        var maskWidth = $(window).width();
        $("body").append('<div id="mask"/>');
        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });
        $('#mask').fadeIn(1000);
        $('#mask').fadeTo("slow", 0.7);
        var winH = $(window).height();
        var winW = $(window).width();
        $(id).css('top', winH / 2 - $(id).height() / 2 - 20);
        $(id).css('left', winW / 2 - $(id).width() / 2 - 20);
        $(id).fadeIn(2000);
        $('.window .close').click(function (e) {
            e.preventDefault();
            $('#mask').hide();
            $('.window').hide();
            $('#mask').remove();
        });

        //if mask is clicked
        $('#mask').click(function () {
            // $(this).hide();
            //$('.window').hide();
            //$(this).remove();
        });


        $.cookie('Brit_vidests', '1', { expires: 60 });
    }

});

JSFiddle

Upvotes: 0

Views: 3328

Answers (2)

Manoj Kumar
Manoj Kumar

Reputation: 111

The JQuery Cookie does not work in Chrome Browser. So, after hours of analysis today I found a solution to use javascript Storage API to accomplish this. I just wanted to share my findings here. You can check JQuery Cookie not working on chrome to know details.

Upvotes: 0

sfboards
sfboards

Reputation: 21

Open up the console in Chrome, there you'll see what the problem is:

Resource interpreted as Script but transferred with MIME type text/plain:
"https://raw.github.com/carhartl/jquery-cookie/master/jquery.cookie.js".
Refused to execute script from 'https://raw.github.com/carhartl/jquery-cookie/master/jquery.cookie.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.

You are embedding a script directly from github, but github serves it with MIME type "text/plain" instead of "text/javascript".

Upvotes: 2

Related Questions