Js closes the modal window to refresh the parent page or jump to the page

Source: Internet
Author: User

There are two windows: window A (parent) and window B (Modal)

Window A contains a datagrid and A button.

When you click the button, the B window (Modal) is displayed ). Add data in window B. After submission, ask window B to close itself, and refresh window A (parent)
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function openSubWin ()
{
Required parameter showmodaldialog(' B .html ', 'newwindow', 'height = 500, width = 400, top = 0, left = 0, toolbar = no, menubar = yes, scrollbars = yes, resizable = yes, location = no, status = no ');
Window. location. reload ();
}
</Script>

Pop-up window B .html. When the child form is closed, the parent page is refreshed.

When we were working on the material system recently, we had to worry about the modal window. We didn't encounter so many things last time. Please remember.
Parent window js method
Copy codeThe 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. You can also add
<META HTTP-EQUIV = "pragma" CONTENT = "no-cache">
<META HTTP-EQUIV = "Cache-Control" CONTENT = "no-cache, must-revalidate">
Subwindow js method:
Copy codeThe Code is as follows:
Function reVal (){
Window. returnValue = 1; // answer value in the parent window
Window. close ();
}

After the modal window is opened, the parent window will wait until the child window returns a value. If it is a form submission or button, the reVal () method will be executed.
Returns the answer value. window. returnValue = 1. I tested it and it seems that only the String type can be returned.

It is difficult to use window. opener. location. reload (); In the subwindow. We will not try it for the modal window. window. opern ()

Another problem is: form submission in the modal window will pop up a new window, which is simply added in This can be done. Note: I didn't want to submit it through form at the beginning. I used js window. location. href to jump to different actions for processing and found that
<Base target = "_ self"> does not work. It seems that <base target = "_ self"> only works for form action =, iframe should be used for implementation.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.