问题
I use primefaces lightbox component with seam. I have a firstpage.xhtml page, where I have a button that display a lightbox with iframe parameter, that will display a secondpage.xhtml that have some form fields and a "Close Window" button.
Code of firstpage.xhtml
> <ui:composition xmlns="http://www.w3.org/1999/xhtml"
> xmlns:ui="http://java.sun.com/jsf/facelets"
> xmlns:h="http://java.sun.com/jsf/html"
> xmlns:f="http://java.sun.com/jsf/core"
> xmlns:p="http://primefaces.prime.com.tr/ui"
> xmlns:opt="http://primefaces.prime.com.tr/optimus"
> template="layout/template1.xhtml"> <ui:define name="head">
> <p:resources/> </ui:define>
> <ui:define name="body">
>
> <h1 class="title">LightBox - External URL</h1> <div class="entry">
> <p>LightBox can display external urls in an iframe.</p>
>
> <p:lightBox id="light" iframe="true" width="80%" height="80%" widgetVar="dlg">
>
> <h:outputLink value="#{request.contextPath}/PermissionEdit.seam" title="PrimeFaces
> HomePage">
> <h:outputText value="PrimeFaces HomePage"/>
> </h:outputLink>
> </p:lightBox>
>
> <h3>Source</h3> <pre name="code" class="xml"> <p:lightBox iframe="true" width="80%" height="80%"> <h:outputLink
> value="http://primefaces.org" title="PrimeFaces HomePage">
> <h:outputText value="PrimeFaces HomePage"/>
> </h:outputLink> </p:lightBox> </pre>
>
> </div> </ui:define> </ui:composition>
Could please someone tell me how to implement a close method to close this lightbox iframe window when i click on the close button on the secondpage.xhtml?
Thanks in advance
回答1:
Reloading a page could be very expensive:
onclick="javascript:window.parent.location.reload(true);"
You can use slightly different approach:
<p:lightBox id="light" iframe="true" width="80%" height="80%" widgetVar="dlg">
on iframe side:
<p:commandButton value="Close" onsuccess="parent.dlg.hide();" ajax="true" process="@none" />
来源:https://stackoverflow.com/questions/7874254/close-a-lightbox-primefaces-from-iframe-button