[英]How to detect if browser supports dialog
此處發布的是一個答案,指示那些錯過舊window.showModalDialog
JavaScript 函數的人使用
<dialog>
元素代替。 我已經將它與 IE 和 FF 所需的 polyfill 一起使用,並且它有效。 但是,在使用我希望在 Chrome 中避免的 polyfill 時引入了明顯的延遲(更不用說在瀏覽器支持時不使用 polyfill 的警告)。 如何檢測是否支持對話框元素,以便我可以省略 polyfill 處理? 特別是這些行:
var dialog = document.getElementById('<element id>');
dialogPolyfill.registerDialog(dialog);
你可以寫一個這樣的簡單測試:
if (typeof HTMLDialogElement === 'function') { /** yep */ } else { /** nope */ }
試試console.log(typeof window.showModalDialog === 'undefined')
if (typeof window.showModalDialog === 'undefined') { console.log('No. '); } else { console.log('Yes! '); }
function dialogElementSupported() { return typeof document.createElement('dialog').show === 'function'; }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.