Web App技术: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) {
}
}
答案 0 :(得分:0)
我添加了以下代码以绕过仅针对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
}