1. 程式人生 > >window.open()頁面之間函數傳值

window.open()頁面之間函數傳值

模式 eww 建立 子窗體 name col 觸發 disabled 寬度

  項目中遇到的問題,使用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()頁面之間函數傳值