DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   JavaScript / DHTML / AJAX (http://www.daniweb.com/forums/forum117.html)
-   -   Displaying cookie contents in safari? (http://www.daniweb.com/forums/thread103853.html)

earachefl@comca Jan 7th, 2008 3:12 pm
Displaying cookie contents in safari?
 
Hi all, I'm learning JavaScript and have run into a problem. Displaying the contents of a cookie with the code
 alert(document.cookie); 
works fine in Firefox 2.0.0.11, but in Safari 3.0.4, it just displays an empty alert box. Any quick answers? Any resources that you can point me to? Thanks in advance, and here's the complete code:

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN" 
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>App 8.1</title>

<script type="text/javascript" >
<!--
        function submitForm(form) {
                document.cookie = "userName=" + form.userName.value;
                alert(document.cookie);
                if(form.userName.value == "") {
                        alert("No name was entered.");
                        return false;
                }
                else {
                        alert("Cookie value is\n" + document.cookie);
                        return false;
                }
        }
//-->
</script>
</head>

<body>
<form>
        Your name here:
        <input type="text" name="userName" value="">
        <input type="button" name="submit" value="Submit!" onClick="submitForm(this.form);">
</form>

</body>
</html>

MidiMagic Jan 8th, 2008 2:58 pm
Re: Displaying cookie contents in safari?
 
It may be a difference in the way a particular browser stores cookies.

~s.o.s~ Jan 10th, 2008 12:34 pm
Re: Displaying cookie contents in safari?
 
Read the part about document.cookie on this page. You are missing some important bits and pieces in your cookie creation code. Also it would be interesting to note that the cookie property of the document is not of type string though it normally is treated like one. Taking care of this should most probably solve your issue.


All times are GMT -4. The time now is 3:39 pm.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC