


Layer closes the pop-up layer and refreshes the parent interface function implementation method
This article mainly introduces the layer's function of closing the pop-up layer and refreshing the parent interface. It analyzes the common implementation techniques and related operation precautions of using layui's layer to refresh the parent interface when closing the pop-up layer. Friends in need can refer to the following. , hope it can help everyone.
The example in this article describes the layer function of closing the pop-up layer and refreshing the parent interface. Share it with everyone for your reference, the details are as follows:
layer is a web elastic layer component that has been popular in recent years. It has a full range of solutions and is committed to serving developers of all levels. You The pages will easily have a rich and friendly operating experience.
A recent project uses the hui front-end framework, and its pop-up layer uses the layer plug-in. For the pop-up layer, there is an operating experience that everyone knows, that is, to close the pop-up layer, the parent page needs to be refreshed. When I started writing, I fell into my own misunderstanding. After the pop-up layer was successfully processed, what I called was:
var index = parent.layer.getFrameIndex(window.name); parent.location.href=url; parent.layer.close(index);
This is correct, but If written like this, it can only be called from one place. If called from multiple places, it cannot return to the original address, but redirects to a new url address. And just in the middle of my project, a certain pop-up layer was called from two places, so obviously this solution is not suitable and needs to be optimized. After searching on Baidu, I found the following two optimization solutions:
Option 1:
Call the parent interface reload function in the layer pop-up layer
window.parent.location.reload(); var index = parent.layer.getFrameIndex(window.name); parent.layer.close(index);
Option 2:
Call the end callback method of the layer plug-in:
end - the callback triggered after the layer is destroyed
Type: Function, default: null
Whether it is confirmation or cancellation, as long as the layer is destroyed, end will be executed without carrying any parameters.
When the parent window opens the layer pop-up box, add the end callback
function openLayer() { //iframe层 parent.layer.open({ type: 2, title: '修改', shadeClose: false, //点击遮罩关闭 shade: 0.8, area: ['30%', '45%'], maxmin: true, closeBtn: 1, content: [url, 'yes'], //iframe的url,yes是否有滚动条 end: function () { location.reload(); } });
After the layer pop-up box processing is completed, there is no need to call other refresh operation functions. Just close it directly
var index = parent.layer.getFrameIndex(window.name); parent.layer.close(index);
Comparatively speaking, the first solution is better, because in terms of operation logic, manually closing the pop-up box should not trigger a refresh operation. Only when the processing logic of the pop-up box is executed successfully and the function is called to close the pop-up box will the parent interface refresh operation be triggered. Based on this logic, option one should be selected. Option two, the page will be refreshed no matter what, which actually increases the processing pressure of the server for no reason.
Solution 2: can solve the problem of sending the processed results of the sub-page to the parent page of the sub-page.
For layer.js, when a callback occurs to close the pop-up layer of the parent class, the submit of the previous form fails:
How to solve: There are many on the Internet, and some are redirected For ajax requests, close the parent pop-up layer after data transmission:
The following is how to close the parent pop-up layer:
##
var index = parent.layer.getFrameIndex(window.name); //获取窗口索引 parent.layer.close(index); // 关闭layer
$("#myForm").submit(); var index = parent.layer.getFrameIndex(window.name); //获取窗口索引 setTimeout(function () { parent.layer.close(index); // 关闭layer },500);
Detailed explanation of layer parent-child page interaction in the layui framework
The layer front-end component in layui implements the image display function
jQuery, layer realizes the opening and closing function of the pop-up layer. Detailed explanation of examples
The above is the detailed content of Layer closes the pop-up layer and refreshes the parent interface function implementation method. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



When you browse the web on your iPhone, the loaded content is temporarily stored as long as the browser app remains open. However, the website updates content regularly, so refreshing the page is an effective way to clear out old data and see the latest published content. This way, you always have the latest information and experiences. If you want to refresh the page on iPhone, the following post will explain you all the methods. How to Refresh Web Pages on Safari [4 Methods] There are several methods to refresh the pages you are viewing on the Safari App on iPhone. Method 1: Use the Refresh Button The easiest way to refresh a page you have open on Safari is to use the Refresh option on your browser's tab bar. If Safa

Is the F5 key not working properly on your Windows 11/10 PC? The F5 key is typically used to refresh the desktop or explorer or reload a web page. However, some of our readers have reported that the F5 key is refreshing their computers and not working properly. How to enable F5 refresh in Windows 11? To refresh your Windows PC, just press the F5 key. On some laptops or desktops, you may need to press the Fn+F5 key combination to complete the refresh operation. Why doesn't F5 refresh work? If pressing the F5 key fails to refresh your computer or you are experiencing issues on Windows 11/10, it may be due to the function keys being locked. Other potential causes include the keyboard or F5 key

If there is anything that programmers are afraid of, then I think it might be that the needs have changed again! No, after the author developed a browser-based Web application, the customer said: The program needs to be internal (no) internal (network) ) environment... This means that the Python environment cannot be installed! Who calls us programmers? Why don't we just develop a GUI version? It's not a problem for me... But after hearing the time given, I couldn't calm down... ...In order not to affect the customer's evaluation, we can only give one week! Although it is not difficult to conceive the GUI, it needs to sort out the service and the interactive interface with the user. If not, you will have to write a separate interface for the GUI, which is obviously not enough time. ah. No, let’s think of another way...otherwise we can just use the Web

Page refresh is very common in our daily network use. When we visit a web page, we sometimes encounter some problems, such as the web page not loading or displaying abnormally, etc. At this time, we usually choose to refresh the page to solve the problem, so how to refresh the page quickly? Let’s discuss the shortcut keys for page refresh. The page refresh shortcut key is a method to quickly refresh the current web page through keyboard operations. In different operating systems and browsers, the shortcut keys for page refresh may be different. Below we use the common W

When we use computers to edit word documents, we often don't know where we touched, and the interface suddenly becomes very small. Sometimes the text in the word document cannot be seen clearly. Some people may panic when encountering such a problem, thinking that the computer is malfunctioning. In fact, it is just because you have encountered a certain setting and adjusted the display. So, if you accidentally change the size of the interface display, how should you restore and adjust it? What should I do if the word interface becomes smaller? Below, we will share several ways to solve it. I hope you can easily deal with it when you encounter such a problem. First, we create and open a Word document and perform simple editing operations to show the steps. In the picture below

In the smartphone market, Samsung's Galaxy series has always attracted attention for its excellent performance and innovative design. As the previous generation machine king, Galaxy S23 Ultra has been loved by consumers since its release. As time goes by, new models emerge one after another. So, can this former machine king still compete today? Next, I will share my actual experience in using Samsung Galaxy S23 Ultra and discuss this issue with everyone. First of all, from the appearance design point of view, Galaxy S23 Ultra still maintains Samsung’s consistent sophistication and high-end. Its unique slightly curved screen design not only enhances the overall aesthetics of the phone, but also brings a more immersive visual experience to users. in daily use

For AI, "playing with mobile phones" is not an easy task. Just identifying various user interfaces (UI) is a big problem: not only must the type of each component be identified, but also the symbols used , position to determine the function of the component. Understanding the UI of mobile devices can help realize various human-computer interaction tasks, such as UI automation. Previous work on mobile UI modeling usually relies on the view hierarchy information of the screen, directly utilizing the structural data of the UI, and thereby bypassing the problem of identifying components starting from the screen pixels. However, view hierarchy is not available in all scenarios. This method usually outputs erroneous results due to missing object descriptions or misplaced structural information, so even if you use

The solution to the value disappearing after the react page is refreshed: 1. Refresh the page and check whether the data in the state will be cleared; 2. Use the "const name = location.query.name; const id = location.query.id;" method By adding parameters to the jump link, you can pass the parameters and refresh the page without losing the data.
