开发者

Rails Set a Cookie to ensure gets a Javascript message only once

I am trying to set a cookie so that users only get a javascript only once. However, I am a Rails newbie and have no idea where to begin. Can anyone point in me in th开发者_开发知识库e right direction?


If it's Javascript you're concerned about I would manage the cookie entirely in Javascript. After the message is shown the first time, set the cookie. It's relatively easy to work with cookies in native Javascript, but libraries like this make it a no-brainer: http://code.google.com/p/cookies/ . You could also use localStorage.

Or you're talking about the inclusion of an actual script only one time? You could do this via Rails with a session ( http://www.quarkruby.com/2007/10/21/sessions-and-cookies-in-ruby-on-rails ), or just make that script a function that gets called or ignored based on whether a cookie has been set.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜