Use jquery to open a new window with post _ jquery

Source: Internet
Author: User
This function is implemented in pure JS on the network. This document describes how to use jquery to implement this function. If you need it, you can refer to the function that already exists on the network, is implemented in pure JS. However, the project found that this function is not compatible with Firefox, so I have rewritten this method.

The Code is as follows:


// New window configuration by default
Var windowDefaultConfig = new Object;
WindowDefaultConfig ['directory'] = 'no ';
WindowDefaultConfig ['location'] = 'no ';
WindowDefaultConfig ['menubar '] = 'no ';
WindowDefaultConfig ['resizable'] = 'yes ';
WindowDefaultConfig ['rollbars'] = 'yes ';
WindowDefaultConfig ['status'] = 'no ';
WindowDefaultConfig ['toolbar '] = 'no ';


The Code is as follows:


/**
* JQUERY implementation for opening a new window in the form of POST
@ Param: url to be opened
@ Param: args URL parameter. The data type is object.
@ Param: name refers to the name of the URL window to be opened. If the same button needs to be opened repeatedly,
Instead of refreshing the window opened for the first time, this parameter should be different each time
@ Param: windowParam parameter configuration for the newly opened window
* @ Author: haijiang.mo
*/
Function jQueryOpenPostWindow (url, args, name, windowParam ){


// Create a form object
Var _ form = $ ("",{
'Id': 'template ',
'Method': 'post ',
'Action': url,
'Target': name,
'Style': 'display: none'
}). AppendTo ($ ("body "));

// Add hidden fields to the form
For (var I in args ){
_ Form. append ($ ("", {'Type': 'ddn', 'name': I, 'value': args [I]});
}

// Clone window parameter object
Var windowConfig = clone (windowDefaultConfig );

// Configuration window
For (var I in windowParam ){
WindowConfig [I] = windowParam [I];
}

// Window configuration string
Var windowConfigStr = "";

For (var I in windowConfig ){
WindowConfigStr + = I + "=" + windowConfig [I] + ",";
}

// Bind the submitted trigger event
_ Form. bind ('submit ', function (){
Window. open ("about: blank", name, windowConfigStr );
});

// Trigger the submission event
_ Form. trigger ("submit ");
// Delete a form
_ Form. remove ();
}


Record it and you can use it later.
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.