打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
关于 Chrome 37+ 中 showModalDialog 被停用的临时解决方案

升级到 Chrome 37 正式版后,发现前端应用中所有使用 window.showModalDialog 的地方都抛了异常,调试发现 window 对象下找不到 showModalDialog 方法。原来,Chrome在许久以前就在控制台上提示使用 window.open 加跨window的 postMessage 方法来替代。终于在Chrome 37正式版暴发了,Chrome全面禁用了 showModalDialog 这个API方法,十分坑嗲。


值得庆幸的是,Google公司考虑到尚有许多企业级应用对此API有严重依赖,一时不容易做出完全调整,于是提供我们一个“修改Chrome策略(EnableDeprecatedWebPlatformFeatures)”以使之工作的临时解决方案,或者说是缓冲方案。之所以是说是临时解决方案,主要是基于两点:一是该API最终还是将寿终正寝,被完全删除 (大概时间是到2014-04-30);二是方案本身并非面对普通用户,具有一定的专业性。因此,终极解决方案还是使用 window.open 加 window.postMessage 替代。或者更好的办法是使用 Div 封装的 Dialog。


现在我们分别针对 Window 系统和 Linux 系统来详细描述一下该临时方案。


一、Window 系统 —— 编辑“组策略”,增加 Chrome 策略配置


这里,因为我的系统是 Window7, 所以我们就以 Window 7 为例来说明。



  1. 运行“组策略编辑器”


通过“开始”菜单或“Win + R”打开“运行”窗口,并输入 “gpedit.msc” 打开系统的“组策略编辑器”。




  1. 增加 Chrome 策略


右击“Local Computer Policy(本地计算机策略) - Computer Configurateion(计算机配置) - Administrative Template(管理模板)”选择“Add/Remove Template...(增加/删除模板)”打开“Add/Remove Template (增加/删除模板对话框)”,点击增加,选择附件中“policy_templates/windows/adm/en-US”下的 chrom.adm 并确定。

(注意: en-US 为操作系统对应的 Locale 配置。)





  1. 配置 “EnableDeprecatedWebPlatformFeatures” 策略项


展开“Classic Administrative Templates(ADM)(经典管理模板)- Google - Chrome”,在右侧列表中找到“Enable deprecated web platform features (启用过时的Web平台功能)"。



右击,选择“Edit(编辑)”。



在“Enable deprecated web platform features (启用过时的Web平台功能)"对话框中选择“Enable(启用)”。



在“Options(选项)”框中点击“Show(显示)”按钮,输入“ShowModalDialog_EffectiveUntil20150430”(表示设置有效期到2015年4月30日)。



二、Linux 系统 —— 增加Chrome策略配置文件


这里,我们以Ubuntu为例进行说明。


Policy configuration files live under /etc/chromium  for Chromium, and under/etc/opt/chrome  for Google Chrome.  There are two sets of policies kept in these directories: one set that is required and mandated by an administrator, and one set that is recommended for users but not required.  These two sets live at:/etc/opt/chrome/policies/managed//etc/opt/chrome/policies/recommended/


  1. 创建策略配置目录,并配置“写”权限


$ sudo -i$ mkdir /etc/opt/chrome/policies$ mkdir /etc/opt/chrome/policies/managed$ mkdir /etc/opt/chrome/policies/recommended$ chmod -w /etc/opt/chrome/policies/managed


  1. 创建策略文件“chrome.json”(其它名字好像也行,没试过),写入以下内容


// Policy template for Linux.{  // Enable deprecated web platform features  //-------------------------------------------------------------------------  // Specify a list of deprecated web platform features to re-enable.  This  // policy gives administrators the ability to re-enable deprecated web  // platform features for a limited time. Features are identified by a string  // tag and the features corresponding to the tags included in the list  // specified by this policy will get re-enabled.  The following tags are  // currently defined: - ShowModalDialog_EffectiveUntil20150430  If this policy  // is left not set or the list is empty, all deprecated web platform features  // will remain disabled.  "EnableDeprecatedWebPlatformFeatures": ["ShowModalDialog_EffectiveUntil20150430"]}


  1. 拷贝“chrome.json”到“/etc/opt/chrome/policies/managed”目录:


$ cp chrome.json /etc/opt/chrome/policies/managed

三、查看结果


在 Chrome 中输入“chrome://policies”.



四、参考



  1. Dev.Opera: https://dev.opera.com/blog/showmodaldialog/

  2. Blink-dev: https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/xh9fPX0ijqk/ixHZCOH6GLgJ

  3. Set Chrome policies for devices: https://support.google.com/chrome/a/answer/187202?hl=en&ref_topic=4386995

  4. Documentation for Administrators: http://dev.chromium.org/administrators

  5. Disabling showModalDialog: http://blog.chromium.org/2014/07/disabling-showmodaldialog.html


五、附件


Policy Templates


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Chrome 策略管理的那些事
SPARK的安装和部署
解决浏览器错误STATUS_INVALID_IMAGE_HASH
XAMPP开机启动
showModalDialog()的使用
乐视盒子 改造成下载机、NAS主机
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服