Home >Web Front-end >JS Tutorial >js closes the modal window and refreshes the parent page or jumps to the page_javascript skills

js closes the modal window and refreshes the parent page or jumps to the page_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:46:441167browse

There are two windows: A window (parent), B window (modal)

There is a DATAGRID and a button in the A window.

When the button is clicked, window B (modal) pops up. Add data in the B window. After submission, require the B window to close automatically, and then refresh the A window (parent)

Copy code Code As follows:



Pop up the subform b.html, and trigger the parent page to refresh when the subform is closed

When I was working on the material system recently, the issue of modal windows came up again. The last time I worked on it, I didn’t encounter so many things this time. Write it down
Parent window js method
Copy code The code is as follows:

function openwin(id){
var answer=window.showModalDialog("demand.do? method=queryBOM&mdid=" id "&d=" escape(new Date()),window.self,"dialogWidth:700px;dialogHeight:620px:center:yes");
if(answer==1){
window.location.href = "demand.do?method=selmd&d=" escape(new Date()); //Go to the processing page
//window.location.reload(); Refresh the parent window
//winow.location.reload(true);

}
}

Add an escape(new Date()) to avoid reading the cache. Of course, you can also add it in the child window, add


Sub window js method:
Copy code The code is as follows:

function reVal(){
window.returnValue=1; //The value of answer in the parent window
window.close();
}

After opening the modal window, The parent window will wait for the child window to return a value. If it is a form submission or a button, it will execute the reVal() method
to return the value of answer, window.returnValue=1. I tested this place and it seems that it can only return String type. The array type does not work well

Use window.opener.location.reload() in the sub-window; does not work well, do not try to use modal windows, window.opern() works well

There is another problem: submitting the form in the modal window will pop up a new window. This problem can be solved simply by adding
in the . Note: I didn’t want to submit through the form at first. I used js window.location.href to jump to different actions for processing. I found that
didn’t work. It seemed that only works for form action="", which should be implemented using iframe.
Statement:
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