如何确定是否支持window.confirm()? [英] How to determine if window.confirm() is supported?

查看:351
本文介绍了如何确定是否支持window.confirm()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个移动网站,各种设备都在使用它,其中包括一些板载计算机,这些计算机运行的是带有IE 7的Windows Embedded 7的锁定版本.由于某些原因,我无法解释,window.confirm()已损坏,但其他所有JavaScript似乎都无法使用工作.

I have a mobile website that is used by various devices including some onboard computers running a locked down version of Windows Embedded 7 with IE 7. For some reason that I cannot explain, window.confirm() is broken, yet all other javascript seems to work.

在连接确认处理程序之前,我什至添加了以下检查,但是单击链接根本无济于事.

I even added the following check before wiring up the confirm handler, but clicking the link simply does nothing.

        if (window.confirm)
        {
            $(".logoff").click(function () 
            {
                return confirm("Are you sure you want to log off?");
            });
        }

如果我删除了点击处理程序,则该链接将正常运行.有没有更好的方法来测试confirm()支持?

If I remove the click handler, the link functions as normal. Is there a better way to test for confirm() support?

推荐答案

尽管以下建议的方法在我测试的每个台式机浏览器中均有效,但它们在设备上的评估结果均为true,但仍未显示对话框或导航至链接到锚的href中.

While the following suggested methods worked in every desktop browser I tested, they all evaluated to true on the device and still didn't display a dialog or navigate to the link in the anchor's href.

if (typeof confirm == 'object')
if ('confirm' in window && typeof window.confirm === 'object')
if (window.confirm)

(在IE 7中,typeof somefunction'object'而不是'function')

(In IE 7, typeof somefunction is 'object' instead of 'function')

我的解决方案是根据@ThiefMaster的建议,使用 jQuery UI对话框.

My solution was to use a jQuery UI Dialog instead, based on @ThiefMaster's suggestion.

这篇关于如何确定是否支持window.confirm()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆