rhyswynne
09-14-2006, 07:12 AM
Hi everybody, I am designing a website for a client which sells tobacco. By law, we have to put a confirmation box before accessing each page. However, once the user clicks "OK" to view the content, we don't have to pester them further (so if the user wants to view different tobacco products, they can without clicking an alert box anymore). I have drafted out some code using session cookies (with some libraries obtained off the internet), but I don't get an alert box at all. I assume I'm very close to completion, so any assistance would be great.
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!--
function writeSessionCookie (cookieName, cookieValue) {
document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
return true;
}
function get_cookie(Name) {
var search = Name + "=";
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
// if cookie exists
if (offset != -1) {
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function checkCount() {
if (getCookieValue ("count")) {
}
else
{
input_box=confirm("Click OK or Cancel to Continue");
if (input_box==true)
{
// Output when OK is clicked
writeSessionCookie("count", "1");
}
else
{
// Output when Cancel is clicked
window.location = "http://www.google.co.uk";
}
}
}
// End -->
</script>
</head>
<BODY OnLoad="checkCount()">
<p>Page!<p>
</body></html>
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!--
function writeSessionCookie (cookieName, cookieValue) {
document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
return true;
}
function get_cookie(Name) {
var search = Name + "=";
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
// if cookie exists
if (offset != -1) {
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function checkCount() {
if (getCookieValue ("count")) {
}
else
{
input_box=confirm("Click OK or Cancel to Continue");
if (input_box==true)
{
// Output when OK is clicked
writeSessionCookie("count", "1");
}
else
{
// Output when Cancel is clicked
window.location = "http://www.google.co.uk";
}
}
}
// End -->
</script>
</head>
<BODY OnLoad="checkCount()">
<p>Page!<p>
</body></html>