Use jquery to open a new window with post

Source: Internet
Author: User

This function is already available on the network and is implemented in pure JS. However, the project found that this function is not compatible with Firefox, so I have rewritten this method.
Copy codeThe 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 ';

Copy codeThe 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 =$ ("<form> </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 ($ ("<input>", {'type': 'den den ', '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.

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.