Method 1
Recently, when I was working on a web project, I encountered the function of passing parameters across pages, that is, to bring the content of the current page to a new subform. The previous method was to pass an id, then read the database content in the new window. Although it is not very troublesome, if the content is saved in the database, it cannot be implemented only when the draft status is taken. Users often think it is a bug. Consider using the get method to pass, serialize all the required content, and then use the url to transfer it, it looks very bloated, and the length of the get transfer content is limited. As a result, the post method is used for transmission. The problem is that the open method cannot be used to set the request method. Generally, the post on a webpage is implemented through form. If you only simulate the form submission method, the parameters in the open method that can set the form attributes cannot be used. Finally, we try to combine the two methods to set the target of form to the same value as the name parameter of open, and automatically identify the content through the browser to post the content to the new window.
It is interesting that the onsubmit event cannot be triggered directly by calling the form submit method. The help document must be manually triggered. Otherwise, the page can only be refreshed without opening a new window. Only one parameter content is passed in the code, and multiple parameters can be passed.
The Code is as follows:
Copy codeThe Code is as follows:
<Script>
Function openPostWindow (url, data, name)
{
Var tempForm = document. createElement ("form ");
TempForm. id = "tempForm1 ";
TempForm. method = "post ";
TempForm. action = url;
TempForm.tar get = name;
Var hideInput = document. createElement ("input ");
HideInput. type = "hidden ";
HideInput. name = "content"
HideInput. value = data;
TempForm. appendChild (hideInput );
TempForm. attachEvent ("onsubmit", function () {openWindow (name );});
Document. body. appendChild (tempForm );
TempForm. fireEvent ("onsubmit ");
TempForm. submit ();
Document. body. removeChild (tempForm );
}
Function openWindow (name)
{
Window. open ('about: blank ', name, 'height = 400, width = 400, top = 0, left = 0, toolbar = yes, menubar = yes, scrollbars = yes, resizable = yes, location = yes, status = yes ');
}
</Script>
Method 2
Copy codeThe Code is as follows:
Function openappswwithpost (url, name, keys, values)
{
Var newWindow = window. open (url, name );
If (! NewWindow)
Return false;
Var html = "";
Html + = "If (keys & values)
{
Html + = "<input type = 'den den 'name = '" + keys + "'value ='" + values + "'/> ";
}
Html + = "</form> <script type = 'text/javascript '> document. getElementById ('formid'). submit ();";
Html + = "<\/script> </body> Newmediaworkflow Doc ument. write (html );
Return newWindow;
}
The first method is recommended. The second method is found to conflict with the calendar pop-up box during the test. If there is a calendar pop-up box on the subpage, the Calendar box will be refreshed continuously, the Calendar box is not displayed. Of course, it may also be a problem with my calendar box.