2011-05-04 52 views
2

問候javascripts的一部分在瀏覽器中被切斷

我的一個客戶端JavaScript文件失敗。我找到了原因,但這一發現讓我非常困惑,因爲我從未見過這樣的事情。

問題是,當瀏覽器讀取腳本源並輸入包含543行代碼的特定自定義.js文件時,它只會讀取502行,這是if (isValidWidthChange) {,但令我困惑的是當我使用在IE開發者工具和Firefox中的Firebug和使用他們的腳本調試工具,當它擊中線502,JavaScript是切斷像這樣 - if (isValidWidthChan

if (isValidWidthChange) {

if (isValidWidthChan

誰能給我一個邏輯解釋爲什麼發生這種情況?

我可以這麼說,我在文件中添加了一些東西,但是在開始之前我對原件進行了備份,而這實際上是即使在我設置網站使用之後仍會發生的錯誤原始文件再次。

我已經嘗試了很多次IISRESET。我試圖從健康的環境中複製文件。我清除了瀏覽器和服務器上的所有緩存。但它仍然出現。

我自己沒有開發它,它是第三方產品。但這從來沒有發生過。

當錯誤發生時

(function($) { 
    // jQuery autoGrowInput plugin by James Padolsey 
    // See related thread: http://stackoverflow.com/questions/931207/is-there-a-jquery-autogrow-plugin-for-text-fields 
    $.fn.autoGrowInput = function(o) { 
     o = $.extend({ 
      maxWidth: 1000, 
      minWidth: 0, 
      comfortZone: 70 
     }, o); 
     this.filter('input:text').each(function() { 
      var minWidth = o.minWidth || $(this).width(), 
       val = '', 
       input = $(this), 
       testSubject = $('<tester/>').css({ 
        position: 'absolute', 
        top: -9999, 
        left: -9999, 
        width: 'auto', 
        fontSize: input.css('fontSize'), 
        fontFamily: input.css('fontFamily'), 
        fontWeight: input.css('fontWeight'), 
        letterSpacing: input.css('letterSpacing'), 
        whiteSpace: 'nowrap' 
       }), 
       check = function() { 
        if (val === (val = input.val())) { return; } 
        // Enter new content into testSubject 
        var escaped = val.replace(/&/g, '&amp;').replace(/\s/g, '&nbsp;').replace(/</g, '&lt;').replace(/>/g, '&gt;'); 
        testSubject.html(escaped); 
        // Calculate new width + whether to change 
        var testerWidth = testSubject.width(), 
         newWidth = (testerWidth + o.comfortZone) >= minWidth ? testerWidth + o.comfortZone : minWidth, 
         currentWidth = input.width(), 
         isValidWidthChange = (newWidth < currentWidth && newWidth >= minWidth) 
              || (newWidth > minWidth && newWidth < o.maxWidth); 
        // Animate width 
        if (isValidWidthChange) { // This is where it stops 
         input.width(newWidth); 
        } 
       }; 
      testSubject.insertAfter(input); 
      $(this).bind('keyup keydown blur update', check); 
     }); 
     return this; 
    }; 
})(jQuery); 
+2

什麼瀏覽器的量切斷??? – 2011-05-04 12:52:11

+0

還有其他腳本加載嗎?他們可以嗎? – ppumkin 2011-05-04 12:53:19

+1

檢查您的http響應(使用螢火蟲或httpfox)。服務器可能(出於某種原因)不能返回整個腳本。 – 2011-05-04 12:55:14

回答

0

的Codesnippet是否有可能爲你的腳本分成兩個部分? 543行是相當多的代碼,如果至少有一些功能或模塊不能移動到單獨的腳本中,我會感到驚訝。

至於調試問題,您的症狀會建議您的服務器可能有某種最大內容長度。我知道有請求的最大值(最大值?)(有些東西叫做maxAllowedContentLength,這是可配置的),但是如果文件的大小有上限服務,我會感到驚訝。 (坦率地說,這將是愚蠢的,會導致很多問題,但嘿,IIS並不總是聰明 - 或者你的管理員可能太簡陋了?)。檢查最大值是行還是(更可能)字節是很有趣的。所以,檢查一下,你有沒有嘗試過:

  • 添加註釋 - 這是否改變了 斷點?
  • 添加額外的 (未使用)代碼 - 這是否會改變 中斷點?
  • 提供另一個長 腳本,例如,您可以獲得開發者版本 jQuery(而不是縮小的 之一)的 。這也會被打破嗎?

這些實驗的結果和相似,將有助於縮小問題的一點點。

1

這可能是編碼問題,請確保您在所有腳本中沒有特殊字符;

外觀上的字符附近擁有並率,即字符將被瀏覽器忽略,腳本會被他們

/* 
    Mapping GUI to event types 
    Click - clickEvents 
    Purchase -purchaseEvents 
    Consume - consumeEvents 
    Recommended - clickedRecommended 
    Rendered - renderedEvents 
    Rate ײateEvents 
    Blacklist - blacklistEvents 
    Owns ׯwnsEvents 
    Total 

*/