Found a script on the 'net that I want to try and set up, thought that it would be straight forward but finding out that I may be wrong.
It is a simple JavaScript cookie that creates a text box to type into and then store the information on the computer. Once the user comes back again it shows the same information and is like a notepad that is a neat tool!
Want to have something similar for a Flash file on site, but can't seem to get it to work.
The cookie.js is saved within the same directory.
Have the following code in the head of the HTML document:
<SCRIPT LANGUAGE="JavaScript" SRC="cookie.js"><!--
// --></SCRIPT>
<SCRIPT LANGUAGE="JavaScript"><!--
function loadNotes() {
var cookie=document.cookie
if(nameDefined(cookie,"Notes")) {
notes=getCookieValue(cookie,"Notes")
notes=decode(notes)
}else notes=""
document.forms[0].notesArea.value=notes
}
function saveNotes() {
notes=window.document.forms[0].notesArea.value
notes=encode(notes)
var newCookie = "Notes="+notes+"; expires="
newCookie += "Tuesday, 09-Nov-10 23:12:40 GMT"
document.cookie=newCookie
}
function encode(s) {
t=""
for(var i=0;i<s.length;++i) {
ch=s.charAt(i)
if(ch=="/") t += "//"
else if(ch==" ") t += "/b"
else if(ch==",") t += "/."
else if(ch==";") t += "/:"
else if(ch=="\n") t += "/n"
else if(ch=="\r") t += "/r"
else if(ch=="\t") t += "/t"
else if(ch=="\b") t += "/b"
else t += ch
}
return t
}
function decode(s) {
// Decode the encoded cookie value
t=""
if(s==null) return t
for(var i=0;i<s.length;++i) {
var ch=s.charAt(i)
if(ch=="/") {
++i
if(i<s.length){
ch=s.charAt(i)
if(ch=="/") t += ch
else if(ch==".") t += ","
else if(ch==":") t += ";"
else if(ch=="n") t += "\n"
else if(ch=="r") t += "\r"
else if(ch=="t") t += "\t"
else if(ch=="b") t += " "
}
}else t += ch
}
return t
}
// --></SCRIPT>
Then on the text box movie clip inside the flash file have the following:
onClipEvent (load) {
getURL ("javascript:loadnotes()");
}
The movie clip is simply an 'input' text box, with a variable of notesArea for the options.
On the button to submit have:
on (release) {
getURL ("javascript:saveNotes()");
}
It all seems like it should work... but doesn't. As soon as the page is loaded comes up with an error in the corner of the browser, so perhaps something tiny that I am missing.
Suggestions?
Cheers,
Shawn





Bookmarks