2013-03-21 26 views
1

在我們的組織中,我們有一項策略適用於所有用戶,以使IE9進入IE7渲染模式,以便與某些第三方應用程序兼容。我正在使用SignalR和KnockoutJS新的應用程序,我使用IE文檔模式更改不起作用

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

,但由於某種原因,IE瀏覽器不進行切換迫使IE是在IE9模式?如果我進入開發人員工具,它表示該應用程序呈現在IE9模式下,但實際上並不正確。如果我在沒有開發工具的情況下刷新IE瀏覽器就會打開它,但如果我用開發人員工具刷新IE瀏覽器打開應用程序開始工作。同樣手動切換到IE9渲染模式也解決了這個問題。問題是我們有很多用戶,所以爲每個人手動執行此操作都不切實際。

確切的問題是,只有初始化似乎沒有工作。即使在這種混亂的狀態IE瀏覽器可以發佈消息到所有其他客戶端只是當頁面最初加載時沒有帖子返回到應用了ploicy的IE9。該應用程序在Firefox和Chrome中運行良好。

我還在web.config中包含了X-UA兼容標籤,但沒有效果。我對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> 

任何幫助將不勝感激,謝謝!

+1

是否使用'$ .connection.hub.start({transport:「longPolling」})'幫助啓動SignalR連接?使用$ .connection.hub.start({transport:「longPolling」})的 – halter73 2013-03-21 17:44:12

+0

不能解決問題。 – Lukasz 2013-03-21 19:04:50

+0

腳本不會導致此問題 – nav0611 2013-03-22 09:32:22

回答

1

@Lukasz如果您將start()代碼更改爲下面的代碼,會發生什麼情況?

$.connection.hub.start().done(function() { 
console.log("started!"); 
$.connection.messageHub.server.getMessages(); 

    }).fail(function() { 
     console.log("Could not connect!"); 
    }); 
+0

像以前一樣,應用程序的功能仍不會在IE9渲染模式下獲得IE9中的消息。如果我得到開發工具,它實際上說它是在IE9中使用IE9標準模式...沒有做任何事情,如果我關閉開發工具並刷新它的工作... – Lukasz 2013-03-22 17:45:05

+0

不知道開發工具對IE有什麼影響。如果您在IE中打開另一個網站(如bing.com)並打開開發工具,然後導航到您的頁面,控制檯窗口是否會記錄任何錯誤? – DannyC 2013-03-22 18:00:59

0

在這種特定情況下打開了的console.log(「」)線嗆IE9在IE7渲染被迫返回到IE9模式,任何線也不會被調用後模式。從代碼中移除console.log行修復了問題。