S
shree
Hi all,
I'm trying to call javascript function via onLoad but running into a
problem. I would appreciate any help and suggestion.
My application is as follows. When a page loads, I want to check
whether the vistor has the site's cookie present in their browser. If
its not present, then to redirect user to a login page (script). If
the cookie is present, then the rest of the html page should load.
I'm able to get function to detect cookie's presence and direct to
login page correctly when cookie is not present.
If however, cookie is already present, since I'm using onLoad event,
the page is continuously getting loaded and this is causing the browser
to crash. I'm running windows xp, IE 6.0
question/request - can anyone suggest a way to call js function just
once via onLoad. Or any other way to load a function once without
having the user to perform any action as the page loads.
Thank you for your time,
Shree
<html>
<head>
<title>Ex_Detect_Cookie</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script language="JavaScript">
function DetectCookie() {
var tmpcookie = new Date();
chkcookie = (tmpcookie.getTime() + '');
document.cookie = "chkcookie=" + chkcookie + "; path=/";
if (document.cookie.indexOf(chkcookie,0) < 0) {//cookie is present
//if (document.cookie && document.cookie != "") {//cookie present
and is not null
var CurrentPage = document.location.href;
window.location = CurrentPage;
alert ("cookie is present, no need to direct user to login
page");
}
else {
//cookie is not present, redirect user to authentication page.
alert ("cookie is not present, redirect user to login page");
function LaunchCGIprogramText() {
var holderText = new Image();
holderText.src = "http://www.open365test.net/login.pl?" +
document.location.href;
window.location = "http://www.open365test.net/login.pl?" +
document.location.href;
}
LaunchCGIprogramText();
}
}
//-->
</script>
</head>
<body onLoad= 'DetectCookie()'>
<p>Print hello.
</body>
</html>
I'm trying to call javascript function via onLoad but running into a
problem. I would appreciate any help and suggestion.
My application is as follows. When a page loads, I want to check
whether the vistor has the site's cookie present in their browser. If
its not present, then to redirect user to a login page (script). If
the cookie is present, then the rest of the html page should load.
I'm able to get function to detect cookie's presence and direct to
login page correctly when cookie is not present.
If however, cookie is already present, since I'm using onLoad event,
the page is continuously getting loaded and this is causing the browser
to crash. I'm running windows xp, IE 6.0
question/request - can anyone suggest a way to call js function just
once via onLoad. Or any other way to load a function once without
having the user to perform any action as the page loads.
Thank you for your time,
Shree
<html>
<head>
<title>Ex_Detect_Cookie</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script language="JavaScript">
function DetectCookie() {
var tmpcookie = new Date();
chkcookie = (tmpcookie.getTime() + '');
document.cookie = "chkcookie=" + chkcookie + "; path=/";
if (document.cookie.indexOf(chkcookie,0) < 0) {//cookie is present
//if (document.cookie && document.cookie != "") {//cookie present
and is not null
var CurrentPage = document.location.href;
window.location = CurrentPage;
alert ("cookie is present, no need to direct user to login
page");
}
else {
//cookie is not present, redirect user to authentication page.
alert ("cookie is not present, redirect user to login page");
function LaunchCGIprogramText() {
var holderText = new Image();
holderText.src = "http://www.open365test.net/login.pl?" +
document.location.href;
window.location = "http://www.open365test.net/login.pl?" +
document.location.href;
}
LaunchCGIprogramText();
}
}
//-->
</script>
</head>
<body onLoad= 'DetectCookie()'>
<p>Print hello.
</body>
</html>