欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js模式化窗口問題![window.dialogArguments]

 更新時間:2016年10月30日 00:27:54   投稿:mdxy-dxy  
這篇文章主要介紹了js模式化窗口問題![window.dialogArguments],需要的朋友可以參考下

前些天做項目時遇到了個瀏覽器兼容問題,解決后記錄一下,也將模式化的資料放上!

詳細(xì)問題描述:

在火狐瀏覽器中彈出一個子窗口,子頁面中是一個分頁,點下一頁后子頁面會刷新,然后window.dialogArguments對象就丟失了,alert輸出顯示undefined [解決方法見第三項]

最近做網(wǎng)站的時候需要用到模式化窗口功能,也遇到了一些問題,所以查了查資料以解決

1.彈出窗口幾種方法:

a.window.open(pageURL,name,parameters);
b.window.showModalDialog()方法用來創(chuàng)建一個顯示HTML內(nèi)容的模態(tài)對話框(IE 4+支持)
c.window.showModelessDialog()方法用來創(chuàng)建一個顯示HTML內(nèi)容的非模態(tài)對話框(IE 5+支持)

2.顯示樣式問題:所用到的是window.showModalDialog(),此方法彈出的窗口在IE6下顯示比IE7 ,IE8 下高度要小點,所以你可以寫個js 解決這點(IE6下高度需要+35PX左右, dialogLeft 屬性可以根據(jù)屏幕寬度設(shè)置)
代碼片段如下:

 var swidth=window.screen.width;
 if(parseInt(width)>swidth)
 swidth=100;
 else
 swidth=(swidth-parseInt(width))/2;
varwindowStatus="dialogWidth:"+width+"px;dialogHeight:"+height+"px;dialogTop:80px;dialogLeft:"+swidth+"px;center:1;status:no;scroll:no;resizable:no;help:no;";
 
//彈出方法
 if(url.indexOf("?")<0){window.showModalDialog(url+'?setTime='+newDate().getTime(),obj,windowStatus);}
 else{window.showModalDialog(url+'&setTime='+newDate().getTime(),obj,windowStatus);}

3.dialogArguments對象FF瀏覽器中丟失問題: 彈出showModalDialog窗口中需要分頁顯示數(shù)據(jù),點擊頁面中的信息,獲取分頁數(shù)據(jù)的ID,傳給彈出的父窗口。在IE下運行很正常,但在FireFox 3.0中運行時,如果頁面不跳轉(zhuǎn)則可以正常的調(diào)用window.dialogArguments,若頁面一跳轉(zhuǎn)則會丟失window.dialogArguments的引用

現(xiàn)給出2種解決方法:

a.將showModalDialog窗口的頁面放在frameset或者iframe里面,進行一次包裝。
例:
window.showModalDialog("test.aspx");

test.aspx 頁面內(nèi)容

<frameset cols="0,*">
<frame src=""/>
<frame src="分頁顯示數(shù)據(jù)的頁面"/>
</frameset> 

頁面返回方法變成

function returnValue(flag)
{
 var myObj = window.parent.dialogArguments;
 myObj.value = flag;
 window.parent.close();
}

這樣就可以拿到返回的值了

b. 如果不想多弄出來個頁面,可以用下面的方法,此方法可以用到了window.opener.document 對象,此對象IE7,IE8貌似都不支持(本人測試過,不知道在你機器上咋樣),判斷下是什么瀏覽器,然后給父頁面的隱藏域賦值,然后父頁面再處理;

代碼如下:

function returnValue(flag)
 {
 document.getElementById("rValue").value=flag;
 if (window.ActiveXObject) //IE瀏覽器 
 {
 var myObj = window.dialogArguments;
 //alert(myObj);
 myObj.value = flag;
 window.close();
 }
 else{
 window.opener.document.getElementById("hid_oilid").value=flag;
 window.opener.document.getElementById("txt_oil").value=flag+"號";
 //self.close();
 window.close();
 } 
 }

基本所遇到問題均已經(jīng)解決,關(guān)于父頁面與子頁面?zhèn)髦悼梢远鄥㈤喥渌Y料

相關(guān)文章

最新評論