Uncaught TypeError: window.showModalDialog is not a function
时间: 2024-06-12 16:08:56 浏览: 318
Uncaught TypeError: window.showModalDialog is not a function错误的原因是谷歌浏览器已经不支持window.showModalDialog方法了。为了解决这个问题,你可以使用兼容谷歌浏览器的方法来自定义一个模态窗口。下面是一个示例代码:
```javascript
if (!window.showModalDialog) {
window.showModalDialog = function(url, name, options) {
if (window.hasOpenWindow) {
window.newWindow.focus();
}
var re = new RegExp(";", "g");
options = options.replace(re, '","');
options = '{"' + options.replace(/:/g, '":"') + '"}';
options = JSON.parse(options);
var openOptions =
"width=" +
parseInt(options.dialogWidth) +
",height=" +
parseInt(options.dialogHeight) +
",left=" +
(window.screen.width - parseInt(options.dialogWidth)) / 2 +
",top=" +
(window.screen.height - 30 - parseInt(options.dialogHeight)) / 2; window.hasOpenWindow = true;
window.newWindow = window.open(url, name, openOptions);
};
}
function showModal() {
window.showModalDialog(
"http://www.baidu.com",
window,
"dialogWidth:500px;dialogHeight:550px"
);
}
```
如果你遇到了Uncaught TypeError: window.showModalDialog is not a function错误,你可以尝试使用以上代码来解决问题。
阅读全文