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);//原窗口关闭处理流程
    });
    

      

  • 相关阅读:
    A1083. List Grades
    A1075. PAT Judge
    uva 10054 The Necklace 欧拉回路
    uva 1423 / Guess
    poj3164 最小树形图
    uva 11865 stream my contest 最小树形图 朱刘算法
    uva 1494
    获取android源码中遇到的问题
    MTK平台Android项目APK预置方案
    Android Lights
  • 原文地址:https://www.cnblogs.com/barrysgy/p/4398415.html
Copyright © 2011-2022 走看看