window.showModalDialog与window.open()使用

浏览: 203 发布日期: 2017-12-18 分类: html
window.showModalDialog 有些浏览器不兼容,尝试用window.open() 封装替代,需要打开子窗口后向父窗口传递数据。

<html>
<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>

<head></head>
<title>Test dialog</title>

 <input name="selbtn1" type="button" id="selbtn1" onclick="select_Dialog();" value="选择" class="button"/>
<script> 

//选择
function select_Dialog(){

    var returnRes=Dialog('layer.html','window',800,600);
    /*
    if(returnRes)
    {
        var returnArr=returnRes.split("+");
        document.getElementById('kh_id').value=returnArr[0];
        document.getElementById('kh_id_txt').value=returnArr[1];
        document.getElementById('zk').value=returnArr[2];
    }
    */
}

function modalDialog(url, name, width, height){
    if (width == undefined){
        width = 400;
    }
    if (height == undefined){
        height = 300;
    }
    
    if (window.showModalDialog){
        window.open(url,name, 'width=' + (width) + 'px; height=' + (height) + 'px; edge:raised;resizable:yes;scroll:yes;status:no;center:yes;help:no;minimize:yes;maximize:yes;');
    }else{
        x = (window.screen.width - width) / 2;
        y = (window.screen.height - height) / 2;
    
        window.open(url, name, 'height='+height+', width='+width+', left='+x+', top='+y+', toolbar=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, modal=yes');
    }
}

function Dialog(url,name,width,height)
{
    //  测试
     // return showModalDialog(url, name, 'dialogWidth:'+w+'px; dialogHeight:'+h+'px; help: no; scroll: yes; status: no');
     // 
         if (window.showModalDialog)
         {
           window.open(url,name, 'width=' + (width) + 'px; height=' + (height) + 'px; edge:raised;resizable:yes;scroll:yes;status:no;center:yes;help:no;minimize:yes;maximize:yes;');
       }
       else
       {
         x = (window.screen.width - width) / 2;
         y = (window.screen.height - height) / 2;
    
        window.open(url, name, 'height='+height+', width='+width+', left='+x+', top='+y+', toolbar=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, modal=yes');
    }
 }

</script> 


</html>

子窗口返回数据:

window.returnvalue
返回顶部