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="JAVAS CRIPT" TYPE="TEXT/JAVASCRIPT">
function buttonLoad()
{
var button = document.getEle mentById("my_bu tton");
if(isTargetPers on())
{
button.attachEv ent("onClick", markVisit);
}
else {
button.style.vi sibility="hidde n";
}
}
function isTargetPerson( )
{
if (document.docum entElement && (typeof
document.docume ntElement.style .maxHeight!="un defined" )&&
window.XMLHttpR equest && isNewbie() )
return true;
else
return false;
}
function isNewbie()
{
var allcookies = document.cookie ;
var pos = allcookies.inde xOf("newbie=");
//alert(pos);
if (pos == -1)
return true;
else {
var start = pos + 7;
var end = allcookies.inde xOf(";", start);
if(end == -1) end = allcookies.leng th;
var value = allcookies.subs tring(start, end);
if (value == "false")
return false;
}
}
function markVisit()
{
var today = new Date();
today.setFullYe ar(today.getFul lYear() + 1);
document.cookie = "newbie=false;e xpires=" + today.toGMTStri ng();
}
</SCRIPT>
</head>
<BODY>
<div id="search">
<INPUT TYPE="image" id="my_button" src="sp_ie7.gif "
VALUE="somevalu e" onClick=somefun ction");'>
</div>
<script language="javas cript"window.on Load=buttonLoad (); </script>
</BODY>
</html>