Window. open submit content to the new window in post mode _ javascript skills

Source: Internet
Author: User
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. It is interesting that the onsubmit event cannot be triggered directly by calling the form submit method. The help document is viewed and must be triggered manually, otherwise, you can only see page refresh without opening a new window. 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:

The 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

The Code is as follows:


Function openappswwithpost (url, name, keys, values)
{
Var newWindow = window. open (url, name );
If (! NewWindow)
Return false;
Var html = "";
Html + ="

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.