Javascript .Focus 导致 safari 8.1.3 仅在 IPad 上崩溃

Javascript .Focus causing safari 8.1.3 to crash only on IPad

网络应用技术:Asp.Net 4.5

以下 javascript 片段导致 Safari(更新 8.1.3)崩溃。但是它在以前的 safari 版本上运行良好。代码只是在服务器请求后重置焦点以控制。注意:这在 Chrome、IE 和 FF 中工作正常。

var TFoc_Id
function EndRequestHandler() {
    try {
        //Maintain vertical scroll pos in panel
        var panel = document.getElementById("ContentPlaceHolder1_InputPanel1");
            if (panel != null) {
                if (typeof yPos == "number") { panel.scrollTop = yPos; }
            }
        //Reset focus to control after server request
        if (TFoc_Id != null) {
            var id = TFoc_Id;
            //Below causes Safari crash
            if (id.indexOf("ContentPlaceHolder1_") != -1) {
               document.getElementById(TFoc_Id).focus();
            }
        }
     } catch (err) {
     }
}

我添加了以下代码来绕过 ipad 的 .focus。这是一个临时的快速修复。

        function EndRequestHandler(sender, args) {
        try {
            var panel = document.getElementById("ContentPlaceHolder1_InputPanel1");
            if (panel != null) {
                if (typeof yPos == "number") { panel.scrollTop = yPos; }
            }

            if (MobileInfo != "iPad") {
                if (TFoc_Id != null) {
                    var id = TFoc_Id;
                    if (id.indexOf("ContentPlaceHolder1_") != -1) {
                        document.getElementById(TFoc_Id).focus();
                    }
                }
            }

        } catch (err) {
        }
    }

    var MobileInfo

    window.onload = function () {
        MobileInfo = get_mobile_info();
    }

    function get_mobile_info() {
        var retVal
        retVal = "";
        if (navigator.userAgent.match(/Android/i)) { retVal = "Android" };
        if (navigator.userAgent.match(/webOS/i)) { retVal = "webOS" };
        if (navigator.userAgent.match(/iPhone/i)) { retVal = "iPhone" };
        if (navigator.userAgent.match(/iPad/i)) { retVal = "iPad" };
        if (navigator.userAgent.match(/iPod/i)) { retVal = "iPod" };
        if (navigator.userAgent.match(/BlackBerry/i)) { retVal = "BlackBerry" };
        if (navigator.userAgent.match(/Windows Phone/i)) { retVal = "Windows Phone" };
        return retVal
    }