How to close a popup window in Liferay?

↘锁芯ラ 提交于 2019-11-30 16:09:32

Here is the code to close the pop-up, this should be present in the parent page which opens the pop-up:

Liferay version 6.1

Liferay.provide(
        window,
        '<portlet:namespace />closePopup',
        function(popupIdToClose) {

            var A = AUI();

            A.DialogManager.closeByChild('#' + popupIdToClose);
        },
        ['aui-base','aui-dialog','aui-dialog-iframe']
    );

Liferay version 6.2

Liferay.provide(
    window,
    '<portlet:namespace/>closePopup',
        function(popupIdToClose) {

            var popupDialog = Liferay.Util.Window.getById(popupIdToClose);

            popupDialog.destroy();
        },
        ['liferay-util-window']
    );

Here is the code to refresh the portlet which opened the pop-up. This should be present in the parent page which opens the pop-up:

Liferay.provide(
        window,
        '<portlet:namespace />refreshPortlet',
        function() {

            <%-- refreshing the portlet [Liferay.Util.getOpener().] --%>
            var curPortletBoundaryId = '#p_p_id<portlet:namespace />';

            Liferay.Portlet.refresh(curPortletBoundaryId);
        },
        ['aui-dialog','aui-dialog-iframe']
    );

It is up to you how to call the closePopup & refreshPortlet functions. One way is you can let the pop-up refresh and call the closePopup function from the pop-up itself only when the request is successfully processed and then call the refreshPortlet function also from the pop-up.

Here is a code-snippet which would help you to call parent-page functions from the pop-up:

Liferay.Util.getOpener().<portlet:namespace />closePopup(popupIdToClose);
Liferay.Util.getOpener().<portlet:namespace />refreshPortlet();

The popupIdToClose is the same id which is used when opening the pop-up as shown:

taglibEditURL = "javascript:"
                +   Liferay.Util.openWindow({"
                +       "dialog: {width: 960},"
                +       "id: '" + renderResponse.getNamespace() + "'," // This is the "popupIdToClose"
                +       "title: '" + LanguageUtil.format(request.getLocale(), "edit-x", HtmlUtil.escape(assetRenderer.getTitle(request.getLocale()))) + "',"
                +       "uri:'" + HtmlUtil.escapeURL(editPortletURLString)
                +       "'}"
                +   ");";

Hope this helps.

AUI taglib solution for 6.2 version. No additional JS required.

<aui:button cssClass="close-panel" type="cancel" value="close" />

Important part is cssClass="close-panel".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!