深圳全飞鸿

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 705|回复: 0
打印 上一主题 下一主题

chrome中showModalDialog解决方案

[复制链接]

800

主题

1379

帖子

7725

积分

版主

Rank: 7Rank: 7Rank: 7

积分
7725
跳转到指定楼层
楼主
发表于 2021-4-24 11:16:29 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

未测试




调用myShowModalDialog
  1. function myShowModalDialog(url, width, height, callback)
  2. {
  3.     if(window.showModalDialog)
  4.     {
  5.         if(callback)
  6.         {
  7.             var rlt = showModalDialog(url, '', 'resizable:no;scroll:no;status:no;center:yes;help:no;dialogWidth:' + width + ' px;dialogHeight:' + height + ' px');
  8.             if(rlt)
  9.                 return callback(rlt);
  10.             else
  11.             {
  12.                 callback(window.returnValue);
  13.             }
  14.         }
  15.         else
  16.             showModalDialog(url, '', 'resizable:no;scroll:no;status:no;center:yes;help:no;dialogWidth:' + width + ' px;dialogHeight:' + height + ' px');
  17.     }
  18.     else
  19.     {
  20.         if(callback)
  21.             window.showModalDialogCallback = callback;
  22.         var top = (window.screen.availHeight-30-height)/2; //获得窗口的垂直位置;
  23.         var left = (window.screen.availWidth-10-width)/2; //获得窗口的水平位置;
  24.         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";
  25.         window.open(url,window, winOption);
  26.     }
  27. }
复制代码

  


test.html中脚本函数
  1. <script type='text/javascript'>//在点击网页中确定按钮调用SetReturnValue
  2. function SetReturnValue()
  3. {
  4.     var rlt = "我想返回的数值";
  5.     window.returnValue = rlt;//ie之类浏览器
  6.     if(opener != null && opener != 'undefined')
  7.     {
  8.         window.opener.returnValue = rlt; //chrome有些版本有问题, 所以在子窗口同时修改了父窗口的ReturnValue(能执行showModalDialog的chrome)
  9.         if(window.opener.showModalDialogCallback)
  10.             window.opener.showModalDialogCallback(rlt);
  11.     }
  12.     window.close();
  13. }
  14. </script>
复制代码

  

调用方式
  1. myShowModalDialog("http://test.com/test.html", 500, 4000, function(resv){
  2.          alert(resv);//原窗口关闭处理流程
  3. });
复制代码

  
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|nagomes  

GMT+8, 2025-6-29 13:45 , Processed in 0.073436 second(s), 21 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表