Saturday, 15 August 2015

My javascript popup shows for a split second if there's a cookie -



My javascript popup shows for a split second if there's a cookie -

i have no clue i'm doing wrong. works shows popup split second. timeout alternative better? part problem? i'm little new javascript don't know for.

<script language="javascript" type="text/javascript"> /** create html cookie , set expiry day. **/ function createcookie(name,value,days) { var date = new date(); date.settime(date.gettime()+(days*24*60*60*1000)); var expires = date.togmtstring(); document.cookie = name+"="+value+"; expires="+expires+"; path=/"; } /** check if cookie has been created. **/ function readcookie(name) { var flag = 0; var dcmntcookie = document.cookie.split(';'); for(var i=0;i < dcmntcookie.length;i++) { var ck = dcmntcookie[i]; while (ck.charat(0)==' ') { ck = ck.substring(1,ck.length); } if(ck) { cparts = ck.split('='); if (cparts[0] == name) flag=1; } } if(flag) { homecoming true; } else { homecoming false; } } /** check if cookie exists else create new one. **/ function checkcookie(name) { if (readcookie(name)) { document.getelementbyid('google').style.display = "none"; document.getelementbyid('google').style.visibility = "hidden"; } else createcookie(name,"cookie 4 day",1); } </script> <script type="text/javascript"> function closethisdiv() { var opendiv = document.getelementbyid('google'); opendiv.style.display = 'none'; } </script> <body onload="checkcookie('mycookie')"

if goal have element id="google" hidden origin of page display (so never shows), should add together css rule loads in head section this:

#google {display: none;}

or, should add together style element html itself:

<div id="google" style="display:none"></div>

as code written, sounds doing supposed to. waits entire document loaded (including images) , hides element id="google". means item show briefly while page loading , code hide it.

if can't modify css or html google object , you're trying hide possible javascript , google object nowadays in html of page (not added programmatically), can this:

<body> other html here <script> // script executes right before /body tag checkcookie("mycookie") </script> </body>

this @ to the lowest degree not wait images load before hiding it.

javascript cookies popup

No comments:

Post a Comment