Click to See Complete Forum and Search --> : Cookie Trouble


tmbs
12-11-2002, 06:46 PM
Could somebody test the following script for me? I have a script (written by hfraser) setup as an include file to detect a netscape browser 4x and lower. In order to avoid a visistor from seeing the popup window on every page of the site (i have the include file on every page of my site), I would like to have a cookie in place; however the cookie function in the script doesn't seem to work.

Any help would be MUCH appreciated.

<script language="JavaScript" type="text/JavaScript">
function setCookieNav(){
var cookieDies = new Date();
// i set the cookie to expire in a week
cookieDies.setTime(cookieDies.getTime() + 7*24*60*60*1000);
// set the content of the cookie
document.cookie = "visit=true.;expires=" + cookieDies.toGMTString();
}

function getCookieNav(){
var MyCookie = new String(document.cookie);
var myCookieHeader = "visit=";
var MyCookieStart = MyCookie.indexOf(myCookieHeader);

// extract data
// if the cookie does not exist well set one and build your window!
if( MyCookieStart = -1){
setCookieNav();
buildNavInfo();
};
}

function buildNavInfo(){
var br = navigator.appName ;
var brv = navigator.appVersion ;
if(br == "Netscape")
{
if(brv<"5.0")
{
newwindow=window.open("","new1","width=500,height=175");

newwindow.document.write("<font face='arial, helvetica, ms sans serif' size='2'><b>Please note:</b><br><br>Our site is best viewed using Netscape 5.0 or higher browsers. It appears you are using Netscape "+brv+". Please visit <a href='http://www.netscape.com' onClick='window.opener.location=this.href;window.close(); return false'>Netscape</a> for a free copy of a newer version of Netscape.<br><br>If you believe this message is the result of a system error, please contact our <a href='mailto:webmaster@yadayada.com'>webmaster</a>.<p align='right'><a href='javascript:window.close()'>close window</a></p></font>");

newwindow.document.close();
}
}
}
</script>

The following is on every htm page:

<body onLoad="getCookieNav();">

tmbs
12-16-2002, 05:34 PM
Got it? Nope. Still can't seem to get it to work. This is what I have now:

<script language="JavaScript" type="text/JavaScript">
myCookieName = "visit";
myCookieData = null;

function getCookieNav(){
myCookieData = getCookie(myCookieName);

// if the cookie does not exist well set one and build your window!
if( myCookieData == null ){
setCookieNav();
buildNavInfo();
}
}
function setCookieNav(){
var cookieDies = new Date();
// i set the cookie to expire in a week
cookieDies.setTime(cookieDies.getTime() + 7*24*60*60*1000);
// set the content of the cookie
myCookieData = "true";
setCookie(myCookieName, myCookieData, cookieDies);
}

function buildNavInfo(){
var br = navigator.appName ;
var brv = navigator.appVersion ;
if(br == "Netscape")
{
if(brv<"5.0")
{
newwindow=window.open("","new1","width=500,height=175");

newwindow.document.write("<font face='arial, helvetica, ms sans serif' size='2'><b>Please note:</b><br><br>Our site is best viewed using Netscape 5.0 or higher browsers. It appears you are using Netscape "+brv+". Please visit <a href='http://www.netscape.com' onClick='window.opener.location=this.href;window.close(); return false'>Netscape</a> for a free copy of a newer version of Netscape.<br><br>If you believe this message is the result of a system error, please contact our <a href='mailto:webmaster@yadayada.com'>webmaster</a>.<p align='right'><a href='javascript:window.close()'>close window</a></p></font>");

newwindow.document.close();
}
}
}
</script>

Thanks in advance for your help!

tmbs
12-16-2002, 05:55 PM
Ah. Sorry Dave. All I'm getting is a javascript error is my browser. It doesn't say what's wrong or what line or anything. Sorry for being so vague.

tmbs
12-17-2002, 10:10 AM
Try: http://147.208.187.87

Send an email to webmaster@timberline.com and I'll gladly try to repay you. I can also forward you the files I am using.

tmbs
12-18-2002, 08:22 AM
I've copied the functions into my script. The pop-up window now displays, however when I visit the addtional pages within the site the pop-up continues to display.

What I am hoping to accomplish is the pop-up only displays on a users first visit to a page within the site (whether its the home page or a link from a friend to a page within the site).

Seems like the cookie function is not working. Give it a try.

Thanks again for all of your help.

tmbs
12-19-2002, 03:57 PM
I apologize for my ignorance here, but I'm not following you. How do I go about setting those functions in "laymans" terms.