---
title: "兼容ie和火狐(firefox)的window.showModalDialog"
author: "fackyou200"
date: "2014-05-15T00:24:35Z"
tags: []
categories: ["编程语言"]
slug: "ie-firefox-window-showmodaldialog"
draft: false
lastmod: "2014-05-15T00:24:35Z"
id: 2066586
url: "https://fackyou200.iteye.com/blog/2066586"
---

**一.计算Dialog居中位置。**

function CalcShowModalDialogLocation(dialogWidth, dialogHeight) {  
    var iWidth = dialogWidth;  
    var iHeight = dialogHeight;  
    var iTop = (window.screen.availHeight - 20 - iHeight) / 2;  
    var iLeft = (window.screen.availWidth - 10 - iWidth) / 2;  
    return 'dialogWidth:' + iWidth + 'px;dialogHeight:' + iHeight + 'px;dialogTop: ' + iTop + 'px; dialogLeft: ' + iLeft + 'px;center:yes;scroll:no;status:no;resizable:0;location:no';  
}  
**二.调用Dialog位置方法。**

var DialogLocation = CalcShowModalDialogLocation(500, 260);  
var result = window.showModalDialog("URL", window, DialogLocation);