Home Web Front-end JS Tutorial Layer closes the pop-up layer and refreshes the parent interface function implementation method

Layer closes the pop-up layer and refreshes the parent interface function implementation method

Jan 18, 2018 pm 04:34 PM
refresh interface

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);
Copy after login

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);
Copy after login

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();
      }
});
Copy after login

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);
Copy after login

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
Copy after login

Use ajax This works, but what I am doing is payment. The page needs to pop up before I can pay, and it cannot be converted to ajax. How can I help? Later, my boss said: "Can't you execute the shutdown later?" This is an idea that would be nice to try.

Attached code:


$("#myForm").submit();
var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
setTimeout(function () {
  parent.layer.close(index); // 关闭layer
},500);
Copy after login
I also need to open a window after closing the parent class window, how to solve it, later I found that layer.js left There is a good way, that is to call the method of the parent window. This is not affected by the child window. Pass: parent. Parent class method name (parameter). This is enough. Call the layer.js pop-up in the parent window. alright.

Related recommendations:


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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

6 Ways to Refresh Web Pages on iPhone 6 Ways to Refresh Web Pages on iPhone Feb 05, 2024 pm 02:00 PM

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

F5 refresh key not working in Windows 11 F5 refresh key not working in Windows 11 Mar 14, 2024 pm 01:01 PM

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

Python tips can still implement graphical interface without using Gui Python tips can still implement graphical interface without using Gui Apr 12, 2023 pm 04:43 PM

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

How to quickly refresh a web page? How to quickly refresh a web page? Feb 18, 2024 pm 01:14 PM

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

What should I do if the word interface becomes smaller? What should I do if the word interface becomes smaller? Mar 20, 2024 pm 09:30 PM

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

Can the previous machine emperor fight again? Samsung Galaxy S23 Ultra practical experience sharing Can the previous machine emperor fight again? Samsung Galaxy S23 Ultra practical experience sharing Mar 12, 2024 pm 01:58 PM

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

Two Chinese Google researchers released the first purely visual 'mobile UI understanding' model, four major tasks to refresh SOTA Two Chinese Google researchers released the first purely visual 'mobile UI understanding' model, four major tasks to refresh SOTA Apr 12, 2023 pm 04:40 PM

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

What should I do if the value disappears after the react page is refreshed? What should I do if the value disappears after the react page is refreshed? Dec 29, 2022 am 11:11 AM

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.

See all articles