zoukankan      html  css  js  c++  java
  • chrome中showModalDialog解决方案

    调用myShowModalDialog

    function myShowModalDialog(url, width, height, callback)
    {
    	if(window.showModalDialog)
    	{
    		if(callback)
    		{
    			var rlt = showModalDialog(url, '', 'resizable:no;scroll:no;status:no;center:yes;help:no;dialogWidth:' + width + ' px;dialogHeight:' + height + ' px');
    			if(rlt)
    				return callback(rlt);
    			else
    			{
    				callback(window.returnValue);
    			}
    		}
    		else
    			showModalDialog(url, '', 'resizable:no;scroll:no;status:no;center:yes;help:no;dialogWidth:' + width + ' px;dialogHeight:' + height + ' px');
    	}
    	else
    	{
    		if(callback)
    			window.showModalDialogCallback = callback;
    		var top = (window.screen.availHeight-30-height)/2; //获得窗口的垂直位置;
    		var left = (window.screen.availWidth-10-width)/2; //获得窗口的水平位置;
    		var winOption = "top="+top+",left="+left+",height="+height+",width="+width+",resizable=no,scrollbars=no,status=no,toolbar=no,location=no,directories=no,menubar=no,help=no";
        	window.open(url,window, winOption);
    	}
    }
    

      

     

    test.html中脚本函数

    <script type='text/javascript'>//在点击网页中确定按钮调用SetReturnValue
    function SetReturnValue()
    {
    	var rlt = "我想返回的数值";
    	window.returnValue = rlt;//ie之类浏览器
    	if(opener != null && opener != 'undefined')
    	{
    		window.opener.returnValue = rlt; //chrome有些版本有问题, 所以在子窗口同时修改了父窗口的ReturnValue(能执行showModalDialog的chrome)
    		if(window.opener.showModalDialogCallback)
    			window.opener.showModalDialogCallback(rlt);
    	}
    	window.close();
    }
    </script>
    

      

    调用方式

    myShowModalDialog("http://test.com/test.html", 500, 4000, function(resv){
             alert(resv);//原窗口关闭处理流程
    });
    

      

  • 相关阅读:
    关于OI的文学作品
    HBOI 2020 游记
    从0开始的字符串生活(选手命要没了)
    近两年HBOI选做
    NOI online #3
    2020年“美团杯”程序设计挑战赛题解(目前只有测试赛)
    退群咕咕墙
    JS 获得当前地址栏url
    你了解getBoundingClientRect()?
    字符串与数字相加
  • 原文地址:https://www.cnblogs.com/barrysgy/p/4398415.html
Copyright © 2011-2022 走看看