goog.net.cookies with clojurescript?

1,593 views
Skip to first unread message

Eric Harris-Braun

unread,
Oct 5, 2011, 5:24:17 PM10/5/11
to Clojure
Has anybody successfully used cookies in clojurescript with
goog.net.cookies?

I keep getting this error: 'this.isValidName' [undefined] is not a
function" (Safari) or "Uncaught TypeError: Object [object DOMWindow]
has no method 'isValidName'" (Chrome) when I try to set a cookie via
goog.net.cookies.set.

Thanks

Jonathan Fischer Friberg

unread,
Oct 6, 2011, 6:38:43 AM10/6/11
to clo...@googlegroups.com
I managed to do it.
The problem is that we need to use the function set in a goog.net.Cookies object.
There is already such an object, which is called goog.net.cookies, see the bottom of the source file:

/**
 * A static default instance.
 * @type {goog.net.Cookies}
 */
goog.net.cookies = new goog.net.Cookies(document);

Therefore we need to do

(ns cookies
  (:require [goog.net.cookies :as cks]))

(defn ^:export setcookie []
  (.set goog.net.cookies "name" "content" -1))

Which will properly set the cookie (see attachment)



--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

cookie_small.png

Eric Harris-Braun

unread,
Oct 6, 2011, 1:06:28 PM10/6/11
to Clojure
Thanks Jonathan! That's it exactly. I had seen goog.net.cookies
(lowercase) and didn't realize it was an object on which to make the
set call. I thought in was another namespace in which to make the
function call, thus I had been writing:

.. (:use [goog.net.cookies :as cookie]) ...

and was calling:

(cookie/set "name" content)

which is what was failing!

Thanks again.

-e

On Oct 6, 6:38 am, Jonathan Fischer Friberg <odysso...@gmail.com>
wrote:
> I managed to do it.
> The problem is that we need to use the function set in a goog.net.Cookies
> object.
> There is already such an object, which is called goog.net.cookies, see the
> bottom of the source file:
>
> /**
>  * A static default instance.
>  * @type {goog.net.Cookies}
>  */
> goog.net.cookies = new goog.net.Cookies(document);
>
> Therefore we need to do
>
> (ns cookies
>   (:require [goog.net.cookies :as cks]))
>
> (defn ^:export setcookie []
>   (.set goog.net.cookies "name" "content" -1))
>
> Which will properly set the cookie (see attachment)
>
> On Wed, Oct 5, 2011 at 11:24 PM, Eric Harris-Braun
> <zippy.314....@gmail.com>wrote:
>
>
>
> > Has anybody successfully used cookies in clojurescript with
> > goog.net.cookies?
>
> > I keep getting this error: 'this.isValidName' [undefined] is not a
> > function" (Safari) or "Uncaught TypeError: Object [object DOMWindow]
> > has no method 'isValidName'" (Chrome) when I try to set a cookie via
> > goog.net.cookies.set.
>
> > Thanks
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clo...@googlegroups.com
> > Note that posts from new members are moderated - please be patient with
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+u...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en
>
>
>
>  cookie_small.png
> 39KViewDownload
Reply all
Reply to author
Forward
0 new messages