码迷,mamicode.com
首页 > Windows程序 > 详细

window.open()页面之间函数传值

时间:2017-07-05 21:22:24      阅读:294      评论:0      收藏:0      [点我收藏+]

标签:作用   lis   cto   height   checked   nal   方式   self   alt+   

  项目中遇到的问题,使用window.open()开一个页面之后,cookie会消失,所以无法一键切肤不管作用,解决方案如下:

window.open()总结:

window.open("sUrl","sName","sFeature","bReplace");
sUrl:可选项。字符串(String)。指定要被加载的HTML文档的URL地址。假如无指定值,则about:blank的新窗口会被显示。
sName:可选项。字符串(String)。指定打开的窗口的名字。这个名字可以用于form或a对象的TARGET属性。此名字也可以使用下列通用名称:_media:IE6.0在浏览器左边的媒体面板内打开sUrl。
_blank:在新窗口中打开sUrl。
_parent:在当前框架的父框架内打开。假如当前框架无父框架,此参数值等同于_self。
_search:IE5.0在浏览器左边的搜索面板内打开sUrl。
_self:sUrl在当前窗口中打开,覆盖当前文档。
_top:在所有框架之外的最顶层窗口中打开sUrl。假如当前窗口无框架结构,此参数值等同于_self。
sFeatures:可选项。字符串(String)。指定窗口装饰样式。使用下面的值。多个之间用逗号隔开。只有当新的浏览器窗口被建立时,此参数的设置才会发生作用。channelmode={yes|no|1|0}指定是否将窗口显示为频道模式。默认值为no。
directories={yes|no|1|0}指定是否显示「链接」按钮。默认值为yes。
fullscreen={yes|no|1|0}指定是否以全屏方式显示窗口。默认值为no。要小心使用全屏模式,因为这种模式会隐藏浏览器窗口的标题栏和菜单。如果没有在页面内提供关闭窗口的功能,用户可以使用ALT+F4快捷键关闭窗口。
height=number设置窗口的高度。最小值为100。
left=number设置窗口左上角相对于桌面的横坐标。单位为像素(px)。
width=number设置窗口的宽度。最小值为100。
top=number设置窗口左上角相对于桌面的纵坐标。单位为像素(px)。
location={yes|no|1|0}设置是否显示浏览器窗口的地址栏。默认值为yes。
menubar={yes|no|1|0}设置是否显示浏览器窗口的菜单栏。默认值为yes。
resizable={yes|no|1|0}设置窗口是否允许被用户改变尺寸。默认值为yes。
scrollbars={yes|no|1|0}设置窗口是否可以具有滚动条。默认值为yes。
status={yes|no|1|0}设置是否显示浏览器窗口的状态栏。默认值为yes。
titlebar= {yes|no|1|0}设置是否显示浏览器窗口的标题栏。除非调用程序是HTML应用程式(HTA)或被信任的对话框,否则此参数将被忽略。默认值为 yes。toolbar={yes|no|1|0}设置是否显示浏览器窗口的工具条。默认值为yes。
bReplace:可选项。布尔值(Boolean)。false|true。false:新打开的文档覆盖历史列表里的当前文档。true:文新打开的文档被简单的添加到历史列表的最后。

返回值:
oNewWindow:对象(Element)。返回对新的window对象的引用。

实例:

 $("#terminalControl").bind("click",function(){
      $("#terminalControl").removeClass();
      $("#terminalControl").addClass("btn_pointToPint " + $.cookie("color"));//先清除class,再增加class,此class我准备在window.open的页面需要获取到
        var keyValue = $("#gridTable").jqGridRowValue("id");
        var rowData = $("#gridTable").jqGrid(getRowData,keyValue);
       if(checkedRow(keyValue)){
          $(this).attr("disabled","disabled");
              $.ajax({ 
               async:true,
           url:${basePath}/ptp/ptpAction_ipValid.do,
           data:{ip:getcellTitle(rowData.ip)},
           beforeSend:function(){
            $("#terminalControl").attr("value",<s:text name="cems.ptp"></s:text>);
           },
           success:function(responseText){
             $("#terminalControl").attr("value",<s:text name="cems.ok"></s:text>);
             $("#terminalControl").removeAttr("disabled");
               var obj = eval("(" + responseText + ")");
            
             if(obj.result == "success"  ){
               var resourceId="";
              $.each(top.authorizeMenuData,function(i,n){
                if(n.text=="点对点控制"&&n.mark=="menu"||n.text=="ptpControl"&&n.mark=="menu"){
                    resoureId=n.id;
                }
              
              }) 
              window.open("${basePath}/ptp/ptpAction_main.do?resourceId="+resoureId,"_black"," toolbar=yes, menubar=yes, scrollbars=yes, resizable=yes,location=no, status=yes",false); 
              
              
             }else if(obj.result == "multi"){
               var ip = $("#ip_input").val();
               dialogOpen({
                id: "ptp",
                      title: "在线设备",
                      url: "/ptp/ptpAction_listUI.do?ip="+ip,
                      width: "500px",
                      height: "1000px",
                      offset:"rb",
                      btn:null,
                 
               })
             }
             else if(obj.result == "connectServerFail"){
                 dialogMsg("连接服务器失败!",0);
             }else if(obj.result == "analyzeError"){
              dialogMsg("服务配置解析数据失败!",0);
             }else if(obj.result == "notOnline"){
              dialogMsg("该设备不在线!",0);
             }else{
              dialogMsg(<s:text name="cems.public.msgFail"></s:text>,0);
               }
          }
          });
        }
       return false;
    });

从window.open的页面获取到button的class:

 var color = window.opener.document.getElementById("terminalControl").className.split(" ")[1];
 $("body").addClass(color);

注意:只能从window.open的url页面才能获取到:window.opener,这样就可以获取到window.open的父级页面上的任何元素。

方法:

1、在父级页面 test.aspx 的点击<input type="button" id="btnShow" onclick="showItem();"  value="显示子窗体"/>按钮触发 ,然后 :

function showItem() {
    var  win = window.open("test2.aspx",null," height=300,width=450,  Left=300px,Top=20px, menubar=no,titlebar=no,scrollbar=no,toolbar=no, status=no,location=no");
}

2: 在子级页面test2.aspx的点击<input type="button" id="btnSelect" onclick="check();"  value="选择"/> 按钮触发,然后:

function check() {
    window.opener.document.getElementById("txtId").value=id;
    window.opener.document.getElementById("txtName").value=name;
}

这样,父级页面的document.getElementById("txtId") 和 document.getElementById("txtName") 2个控件就可以得到子级页面的返回值。

 

window.open()页面之间函数传值

标签:作用   lis   cto   height   checked   nal   方式   self   alt+   

原文地址:http://www.cnblogs.com/goloving/p/7123122.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!