Home >Web Front-end >JS Tutorial >Use jquery to open a new window with post_jquery

Use jquery to open a new window with post_jquery

WBOY
WBOYOriginal
2016-05-16 16:55:071692browse

There is already a function with this function on the Internet, which is implemented in pure JS. However, I found in the project that this function is not compatible with Firefox, so I rewrote this method.

Copy code The code is as follows:

//Default new window configuration
var windowDefaultConfig = new Object;
windowDefaultConfig['directories'] = 'no';
windowDefaultConfig['location'] = 'no ';
windowDefaultConfig['menubar'] = 'no';
windowDefaultConfig['resizable'] = 'yes';
windowDefaultConfig['scrollbars'] = 'yes';
windowDefaultConfig[' status'] = 'no';
windowDefaultConfig['toolbar'] = 'no';

Copy code The code is as follows:

/**
* JQUERY implementation of opening a new window in POST form
@param:url The URL that needs to be opened
@param:args The parameters of the URL, the data type is object
@param:name Open the URL window name, if the same button needs to open a new window repeatedly,
instead of refreshing the window that is opened for the first time, this parameter should be different each time
@param:windowParam Parameter configuration of the newly opened window
* @author: haijiang.mo
*/
function jQueryOpenPostWindow(url,args,name,windowParam){


// Create a form object
var _form = $("
",{
'id':'tempForm',
'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':'hidden','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 submission trigger event
_form.bind( 'submit',function(){
window.open("about:blank",name,windowConfigStr);
});

//Trigger the submission event
_form.trigger( "submit");
//Form removal
_form.remove();
}

Record it so you can use it later.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn