Z
zhengyan11
Hey,
what I try to do is when a user clicked an image button on my
site, I use onClick to trigger a dialog box and at the same time I use
button.attach("onClick", savecookie) to mark this visitor so that next
time he comes back I can recognize him.If he did not click this image
button on my site, next time I would treat him as a new visitor.
My dialog box works as I expected but it seems that savecookie
function does not do its job since I could not find any cookies
stored. I am using IE7. Anyone has any idea about this? It means that
I cannot trigger two functions from one onclick?
<html>
<head>
<TITLE>THIS IS TEST </TITLE>
<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
function buttonLoad()
{
var button = document.getElementById("my_button");
if(isTargetPerson())
{
button.attachEvent("onClick", markVisit);
}
else {
button.style.visibility="hidden";
}
}
function isTargetPerson()
{
if (document.documentElement && (typeof
document.documentElement.style.maxHeight!="undefined" )&&
window.XMLHttpRequest && isNewbie() )
return true;
else
return false;
}
function isNewbie()
{
var allcookies = document.cookie;
var pos = allcookies.indexOf("newbie=");
//alert(pos);
if (pos == -1)
return true;
else {
var start = pos + 7;
var end = allcookies.indexOf(";", start);
if(end == -1) end = allcookies.length;
var value = allcookies.substring(start, end);
if (value == "false")
return false;
}
}
function markVisit()
{
var today = new Date();
today.setFullYear(today.getFullYear() + 1);
document.cookie = "newbie=false;expires=" + today.toGMTString();
}
</SCRIPT>
</head>
<BODY>
<div id="search">
<INPUT TYPE="image" id="my_button" src="sp_ie7.gif"
VALUE="somevalue" onClick=somefunction");'>
</div>
<script language="javascript"> window.onLoad=buttonLoad(); </script>
</BODY>
</html>
what I try to do is when a user clicked an image button on my
site, I use onClick to trigger a dialog box and at the same time I use
button.attach("onClick", savecookie) to mark this visitor so that next
time he comes back I can recognize him.If he did not click this image
button on my site, next time I would treat him as a new visitor.
My dialog box works as I expected but it seems that savecookie
function does not do its job since I could not find any cookies
stored. I am using IE7. Anyone has any idea about this? It means that
I cannot trigger two functions from one onclick?
<html>
<head>
<TITLE>THIS IS TEST </TITLE>
<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
function buttonLoad()
{
var button = document.getElementById("my_button");
if(isTargetPerson())
{
button.attachEvent("onClick", markVisit);
}
else {
button.style.visibility="hidden";
}
}
function isTargetPerson()
{
if (document.documentElement && (typeof
document.documentElement.style.maxHeight!="undefined" )&&
window.XMLHttpRequest && isNewbie() )
return true;
else
return false;
}
function isNewbie()
{
var allcookies = document.cookie;
var pos = allcookies.indexOf("newbie=");
//alert(pos);
if (pos == -1)
return true;
else {
var start = pos + 7;
var end = allcookies.indexOf(";", start);
if(end == -1) end = allcookies.length;
var value = allcookies.substring(start, end);
if (value == "false")
return false;
}
}
function markVisit()
{
var today = new Date();
today.setFullYear(today.getFullYear() + 1);
document.cookie = "newbie=false;expires=" + today.toGMTString();
}
</SCRIPT>
</head>
<BODY>
<div id="search">
<INPUT TYPE="image" id="my_button" src="sp_ie7.gif"
VALUE="somevalue" onClick=somefunction");'>
</div>
<script language="javascript"> window.onLoad=buttonLoad(); </script>
</BODY>
</html>