我們常常透過OpenWindow的方式在瀏覽器上另外開一個視窗,然後透過這視窗另外處理某些功能。但是都只能夠過 HTTP GET的方式傳值,萬一你傳的資料太大,就會造成資料截斷的問題,變成傳值不完整!上Google查了一下,發現原來有這個小技巧可以使用,讓OpenWindow也可以透過POST傳值,這真是太好用了!
它的原理也很簡單,只是透過JavaScript字串去產生一個暫時的FORM,把你的參數用TextArea塞值,然後串起來之後,最後加上一段JavaScript自動送出這個表單。這樣就可以讓你的另外一支程式可以完整的接收傳遞的參數值,非常好用,分享看大家參考!
function OpenWindow2(str_url, str_name, str_width, str_height, dt_param)
{
var oWin = null;
var str_param = "scrollbars=yes,status=yes,resizable=yes,width=%width%,height=%height%";
var m_point = get_mouse_point();
var str_form = "";
var str_form_head = "<form name=\"%form_name%\" action=\"%url%\" method=\"post\">";
var str_form_foot = "</form>";
var str_form_param = "<textarea name=\"%param_name%\" cols=\"20\" rows=\"5\" wrap=\"off\" >%param_value%</textarea>";
var str_javascript_execute = "<script type=\"text/javascript\">document.%form_name%.submit();</sc" + "ript>";
var arr_data = new Array();
str_form_head= str_form_head.ReplaceAll("%form_name%", str_name);
str_form_head= str_form_head.ReplaceAll("%url%", str_url);
arr_data.push(str_form_head);
with (dt_param)
{
for (var col = 0; col < getFieldCount(); col++)
{
var str_param_name = getFieldName(col);
var str_param_value = getValue(str_param_name);
var str = str_form_param;
str = str.ReplaceAll("%param_name%", str_param_name);
str = str.ReplaceAll("%param_value%", str_param_value);
arr_data.push(str);
}
}
arr_data.push(str_form_foot);
str_javascript_execute = str_javascript_execute.ReplaceAll("%form_name%", str_name);
arr_data.push(str_javascript_execute);
//alert(arr_data.join(""));
str_param = str_param.ReplaceAll("%width%", str_width);
str_param = str_param.ReplaceAll("%height%", str_height);
//window.open(str_url, str_name, str_param);
oWin = window.open("", str_name, str_param);
oWin.document.write(arr_data.join(""));
return (oWin);
}
留言列表