Use the jquery implementation to open a new window as post
- 2020-03-30 02:25:15
- OfStack
The network has this function, is to pure JS implementation. However, in the project, I found that this function was not compatible with Firefox, so I overwrote this method.
Write it down for later use.
//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';
function jQueryOpenPostWindow(url,args,name,windowParam){
//Create a form object
var _form = $("<form></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($("<input>",{'type':'hidden','name':i,'value':args[i]}));
}
//Clone the 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]+",";
}
//Binding commit triggers events
_form.bind('submit',function(){
window.open("about:blank",name,windowConfigStr);
});
//Trigger commit event
_form.trigger("submit");
//Form to delete
_form.remove();
}
Write it down for later use.