父页面:
var returnvalue = openShowModalWithParamArray(contextPath+"/common/selector/selector.jsp",param_ary,width,height);
//赋值给全局变量,等待子页面再次触发读取
tparamObj = paramObj;
tvisibleId = visibleId;
thiddenId = hiddenId;
trelate = relate;
/*if(returnvalue){
selectorCallBack(paramObj,visibleId,hiddenId,returnvalue,false,relate);
}*/
function openShowModalWithParamArray(url,paramArray, width, height) {
var height =window.screen.height*0.7;
var width =window.screen.width*0.7;
var top = (window.screen.height-height)/2;
var left = (window.screen.width-width)/2;
var ops = "toolbar=no,menubar=no,location=no,scrollbars=yes,status=yes,resizable=yes,width="+width+",height="+height +",top=" + top + ",left="+left;
var str = JSON.stringify(paramArray);
str = encodeURI(str);
str = $.base64.encode(str);//要引入js
window.open(url+"?o="+str,"", ops);
return treturnvalue;
}
说明:以上是传递json字符串参数的处理手法
function dotest(v){
treturnvalue = v;
selectorCallBack(tparamObj,tvisibleId,thiddenId,treturnvalue,false,trelate);
}
子页面:
var b = getURLParamValue("o");
jsonstr = $.base64.decode(b);
jsonstr = decodeURI(jsonstr);
var params = JSON.parse(jsonstr)[0];
var returnReslut = params.result;// 取值……
function selected() {
window.returnValue = returnReslut;
opener.dotest(returnReslut);//调父页面的js的方法
window.close();
}
/**获取url参数的方法*/
function getURLParamValue(name){
var url = window.location.href;
var index = url.indexOf("?");
if(index<0){
return null;
}
var params = url.substring(index+1).split("&");
for(var i=0;i<params.length;i++){
var ss = params[i].split("=");
if(ss[0]==name && ss.length>1){
return ss[1];
}
}
return null;
}
------------------------------------
/**
* 打开小窗口
* url http连接
* 宽度,h高度,n小窗口名称
*/
function openWindow(url,w,h,n) {
var top = (screen.availHeight-h)/2;
var left = (screen.availWidth-w)/2;
var options = "width=" + w + ",height=" + h + ",";
options += "status=yes,scrollbars=yes,,resizable=yes,location=no,menubar=no,toolbar=no,directories=no,top="+top+",left="+left;
if(n == ""||n==null) {
var date=new Date();
n=date.getSeconds();
}
n=n+"ab";
var newWin=window.open(url,n, options);
newWin.focus();
return newWin;
}