在我们的组织中,我们有一项适用于所有用户的策略,以使 IE9 进入 IE7 呈现模式,以便与某些第三方应用程序兼容。我正在开发一个使用 SignalR 和 KnockoutJS 的新应用程序,并且我正在使用强制 IE 处于 IE9 模式
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
但由于某种原因 IE 没有切换?如果我进入开发人员工具,则表明该应用程序以 IE9 模式呈现,但实际上并不能正常工作。如果我在没有打开开发人员工具的情况下刷新 IE,它就会损坏,但是如果我在使用开发人员工具打开的情况下刷新 IE,应用程序就会开始工作。手动切换到 IE9 渲染模式也可以解决此问题。问题是我们有很多用户,因此为每个人手动执行此操作是不切实际的。
确切的问题是只有 init 似乎不起作用。即使在这种混乱的状态下,IE 也可以在页面最初加载时向所有其他客户端发布消息,在应用了策略的 IE9 上没有返回任何帖子。该应用程序在 Firefox 和 Chrome 中运行良好。
我还在 web.config 中包含了 X-UA-Compatible 标签,但无济于事。我是 SignalR 和 KnockoutJS 的新手,所以也许我错过了什么?
<script>
$(function () {
function Post(message, author, postedDate) {
this.message = ko.observable(message);
this.author = ko.observable(author);
this.postedDate = ko.observable(postedDate);
this.postedDateText = ko.observable("");
}
function PostsViewModel() {
this.hub = $.connection.messageHub;
this.posts = ko.observableArray([]);
this.msg = ko.observable("");
this.lengthRemaining = ko.observable(1000);
this.canPost = ko.computed(function () {
return this.msg().length > 0 && this.msg().length <= 1000;
}, this);
if (ko && ko.bindingHandlers) {
ko.bindingHandlers['jEnable'] = {
'update': function (element, valueAccessor) {
var value = ko.utils.unwrapObservable(valueAccessor());
var $element = $(element);
$element.prop("disabled", !value);
if ($element.hasClass("ui-button")) {
$element.button("option", "disabled", !value);
}
}
};
}
this.msg.subscribe(function (newValue) {
this.lengthRemaining(1000 - newValue.length);
}, this);
this.updateTime = function () {
for (var i = 0; i < this.posts().length; i++) {
console.log(this.posts()[i].postedDate());
var date = new Date(this.posts()[i].postedDate());
var curDate = new Date();
var diff = curDate - date;
if (diff < 60000) {
this.posts()[i].postedDateText("Less than a minute ago");
} else if (diff >= 60000 && diff < 120000) {
this.posts()[i].postedDateText(Math.round(diff / 60000).toString() + " minute ago");
} else if (diff >= 120000 && diff < 3600000) {
this.posts()[i].postedDateText(Math.round(diff / 60000).toString() + " minutes ago");
} else if (diff >= 3600000 && diff < 7200000) {
this.posts()[i].postedDateText("one hour ago");
} else if (diff >= 7200000 && diff < 86400000) {
this.posts()[i].postedDateText(Math.round(diff / 3600000).toString() + " hours ago");
} else {
var month = date.getMonth() + 1;
var day = date.getDate();
var year = date.getFullYear();
this.posts()[i].postedDateText(year + "/" + month + "/" + day);
}
}
};
this.sendPost = function () {
this.hub.server.send(this.msg(), "@User.Identity.Name.Replace(@"ACCOUNTS\","")");
this.msg("");
$("#dialog").dialog("close");
};
this.cancelPost = function () {
$("#dialog").dialog("close");
this.msg("");
};
this.init = function () {
console.log("init");
this.hub.server.getMessages();
window.setInterval(function () { postsViewModel.updateTime(); }, 30000);
};
this.hub.client.populateMessages = function (postsArray) {
console.log("populate posts");
var postsCollection = $.map(postsArray, function (post) {
return new Post(post.message, post.author, post.postedDate);
});
postsCollection.forEach(function (post) {
postsViewModel.posts.push(post);
});
postsViewModel.updateTime();
};
this.hub.client.updateMessage = function (post) {
console.log("received a post");
postsViewModel.posts.unshift(new Post(post.message, post.author, post.postedDate));
postsViewModel.updateTime();
};
};
var postsViewModel = new PostsViewModel();
ko.applyBindings(postsViewModel);
$.connection.hub.start().done(function () {
console.log("started!");
postsViewModel.init();
}).fail(function () {
console.log("Could not connect!");
});
$("#newpost-button").button().click(function () {
$("#dialog").dialog("open");
});
$("#cancel-button").button();
$("#post-button").button();
$("#dialog").dialog({
autoOpen: false,
height: 256,
width: 543,
modal: true,
close: function () {
postsViewModel.cancelPost();
}
});
});
</script>
任何帮助将不胜感激,谢谢!