Hi,
I've spent the past week trying to find a way of setting my site up to use cookies. I don't have any knowledge of any server side script (and my web space I doubt supports it) so I have been looking into javascript as an option and have bought a .....ahem "fun web pages with javascript" book that has taken all the
fun out of my life. The tutorials it provides on the set/get cookie function are very basic and simply don't seem to work for me.
Basically what I'm trying to is provide the following options to visitors to my site.
- A personalised greeting
- The option of email notifications to updates
- The ability to load a different set of pages (ones containing Flash sound players and ones not)
I should state that the pages without the Sound players will still contain Flash movies but small ones that are only used to load the actual sound player movies if required, An option I want to include for 56k users. So I don't need the flash elements to be dynamically loaded.
These all sound like fairly easy things to want to accomplish but it feels as if I am falling short of even the first hurdle. To begin with I have just tried the personalised greeting but with no joy. This is what I have got....
Code:
<head>
<script>
var cString = new String(document.cookie)
var cHead = "crowdsname="
var cstartpos = cString.indexOf(cHead)
if (cstartpos!= -1) {
var cName = cString.substring(cstarpos
+ cHead.length)
document.write("Hi, " + cName + "!")
}
else
{document.write("please enter your name "
+ "and click ok...")
document.write("<FORM NAME=form1>")
document.write("<INPUT TYPE=text NAME=cName "
+ "SIZE=40>")
document.write("<INPUT TYPE=button"
+ " VALUE='OK' onClick='storename()'>")
document.write("</FORM>")
} //EoIF/Else
function storename() {
var cDate = new date()
cDate.setTime(cDate.getTime() + 60*30*1000)
document.cookie = "crowdsname="
+ document.form1.cName.value
+ ";expires=" + cDate.toGMTstring()
} // EoFn storename()
function delcookie(name)
{
document.cookie = name
+"=; expires=Thu, 01-Jan-70 00:00:01GMT" +
";";
alert("Settings deleted! ");
} //EoFn delcookie(name)
</script>
</head>
<body>
<h3>Hi</h3>
<FORM NAME=delcook>
<INPUT TYPE=button NAME=delbutton
VALUE="Remove Settings"
0nClick="delcookie(cHead)">
</form>
</body>
</html> Can anyone help me out here?
Cheers
Crowds