/    Sign up×
Community /Pin to ProfileBookmark

Checking for cookies (JavaScript)

Using JavaScript cookies, cause our hosting package has no server side support, but I’m checking here that the user has cookies on or off….

[code]<script type=”text/javascript”>
var lshow;
lshow = readCookie(“OnTheWayTo”);
if (lshow == “”){
document.write(“<br /><br /><br /><font class=’redcontentfont’>Unfortunately you appear to have Cookies blocked on your browser. This will perhibit you from entering our Adviser section. If you would like to gain access you will have to turn Cookies back <strong>on</strong> using your browser options. For further information on how to do this, please refer to www.aboutcookies.org</font>”);
}
</script>[/code]

was wondering if someone could help because this works fine in FireFox but not in IE…..

any help?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@James_GatkaMar 20.2006 — [CODE]<html>
<head>
<script type="text/javascript">

var expDate = new Date();
expDate.setTime(expDate.getTime()+365*24*60*60*1000); // one year

var errorMsg = "<font class='redcontentfont'>Unfortunately you appear to have Cookies blocked on your browser. This will perhibit you from entering our Adviser section. If you would like to gain access you will have to turn Cookies back <strong>on</strong> using your browser options. For further information on how to do this, please refer to www.aboutcookies.org</font>";


function setCookie(isName,isValue,dExpires){

document.cookie = isName+"="+isValue+";expires="+dExpires.toGMTString();
}

function getCookie(isName){

var cookieStr = document.cookie;
var startSlice = cookieStr.indexOf(isName+"=");
if (startSlice == -1){return false}
var endSlice = cookieStr.indexOf(";",startSlice+1)
if (endSlice == -1){endSlice = cookieStr.length}
var isData = cookieStr.substring(startSlice,endSlice)
var isValue = isData.substring(isData.indexOf("=")+1,isData.length);
return isValue;
}

function init(){

setCookie('test','1',expDate);
if (!getCookie('test'))
{
document.getElementById('noCookie').style.display = '';
document.getElementById('noCookie').innerHTML = errorMsg;
}
}

onload=init;

</script>
</head>
<body>

<div id='noCookie' style='display:none'>&nbsp</div>

</body>
</html>[/CODE]
×

Success!

Help @RabBell spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...