【问题标题】:How to show a popup on a first page visit? (working with Grails)如何在第一页访问时显示弹出窗口? (使用 Grails)
【发布时间】:2013-10-08 22:54:17
【问题描述】:

当用户第一次访问该网站时,必须向用户显示弹出窗口,建议注册时事通讯等等......我想这是通过 cookie 检测完成的。用 Grails 做这件事的正确方法是什么?我们使用 Spring Security Core 插件,但没有找到它对我们有什么帮助。

【问题讨论】:

标签: grails popup


【解决方案1】:

使用过滤器可能很有意义:http://grails.org/doc/latest/guide/theWebLayer.html#filters

如果您需要向所有用户(不仅仅是注册会员)显示弹出窗口,那么 cookie/会话可能是您唯一的解决方案。 如果弹出窗口仅显示给已登录的成员,您可以使用类似于:

showPopupOnFirstLogin(controller:'*', action:'*') {
        before = {
            try{
                User user = springSecurityService.currentUser
                if (user?.mustGetNotification && !request.xhr){
                    //we ignore ajax requests
                    redirect(controller:"home", action:"showPopup")
                    return false
                }

            }catch (Exception e){
                log.error "Failed to redirect", e
            }
        }

}

【讨论】:

  • 我需要向不是注册会员的用户显示弹出窗口,他们只是第一次访问网站。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-23
  • 2015-06-17
相关资源
最近更新 更多