如何在colorbox中提供静态html页面?

时间:2018-04-05 06:48:30

标签: jquery grails colorbox

我的grails应用程序中有很少的静态html页面显示出来。但我发现很难实现这一目标。我需要像js脚本一样显示一个.html文件

function alertExpiry(){
    $.colorbox({iframe:true, width:"50%", height:"50%", href: "expiry.html"});
}

我想要显示expiry.html页面。我把那个html文件放在views / home / expiry.html下 版本:grails 3.2.9

2 个答案:

答案 0 :(得分:0)

如果您想从grails应用程序提供静态页面,则无需在视图目录中添加这些页面,在 web-apps 中创建目录主页将所有静态html文件放在此目录中,如

  

网络应用 - > home - > expiry.html

现在在colorbox jquery插件中获取此资源,如下所示

<div class="popup">
open colorbox
</div>

$(function() {
   $(".popup").colorbox({
    iframe:true,
    width:"500px",
    height:"500px",
    href : "YOUR_APP_NAME/home/expiry.html",
    onClosed:function(){ alert('popup icon closed !')},
   });
});

Grails项目结构:http://www.vogella.com/tutorials/Grails/img/xfirstgrailsapplication10.png.pagespeed.ic.eLfC9gNB16.webp

答案 1 :(得分:0)

UrlMappings 文件中,我添加了以下行

"/page/$id" (controller: "staticPage", action:"index", params:["id": "$id"])

我在 StaticPageController

中写了以下登录信息
class StaticPageController {
    GrailsConventionGroovyPageLocator groovyPageLocator

    def index() {
        if (groovyPageLocator.findViewByPath("/home/${params.id}") != null) {
            return render (view:"/home/${params.id}")
        }
        redirect(controller: "home")
    }
}

我做了一个更改。我将 expiry.html 页面更改为 expiry.gsp ,现在链接为

$.colorbox({iframe: true, width: "50%", height: "50%", href: "page/expiry"});

最后,它按预期工作