Mohammadov
Mohammadov

Reputation: 613

How to load a DIV only one time using COOKIES jquery

So i have a DIV tag with some scripts and i want to load it only one time when a new user subscribe,

this is my code :

<script type="text/javascript">
    /* <![CDATA[ */
    var google_conversion_id = xxxxxx;
    var google_conversion_language = "en";
    var google_conversion_format = "3";
    var google_conversion_color = "ffffff";
    var google_conversion_label = "xxxx-xxx";
    var google_remarketing_only = false;
    /* ]]> */
</script>
<script type="text/javascript" src="/xxx/xx.js">
</script>
<noscript>
    <div style="display:inline;">
    <img height="1" width="1" style="border-style:none;" alt="" src="xxxx"/>
    </div>
</noscript>

Upvotes: 0

Views: 607

Answers (2)

Benny
Benny

Reputation: 53

I suggest using a localStorage , it is simpler than using a cookie

Upvotes: 1

ManiMuthuPandi
ManiMuthuPandi

Reputation: 1604

Try this. Mark your div id as hidden_div and set default to hidden.

    <script>
    if (getCookie("isset")!=1)
    {
    var d = new Date();
    d.setTime(d.getTime() + (1*24*60*60*1000));//24 Hours cookie will be available
    var expires = "expires="+d.toUTCString();
    document.cookie ="isset=1; " + expires;
    $("#hidden_div").show()
    }
    function getCookie(cname) {//Taken from w3schools.com
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1);
    if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
    }
    return "";
    } 
    </script>

Upvotes: 0

Related Questions