2012-04-16 49 views
3

下面我有一個iframe:我得到一個取消定義錯誤的iframe

<iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px;solid;#fff;'></iframe> 

我想下面的停止命令,但我不斷收到一個未定義的錯誤:

$('.upload_target').contentwindow is undefined 

如何解決這個未定義的錯誤?

下面是代碼:

$(".uploadbutton").click(function() { 
      $(".upload_target").contentWindow.stop(); //for anything but IE 
      $(".upload_target").contentWindow.document.execCommand("Stop"); // for IE 
    return stopImageUpload(); 

});

回答

5

您得到undefined,因爲contentWindow是本地JavaScript,並且您正在將它用於jQuery集合,該集合沒有contentWindow作爲值。你必須先獲得原始的DOM對象。做這個,而不是:

$('.upload_target').get(0).contentWindow 
+0

嗨,我沒有得到錯誤,這是偉大的,但我可以問你最後一個問題。上面的代碼是阻止文件上傳,但這似乎不起作用。當用戶點擊.upload按鈕時,你知道如何通過jquery停止文件上傳嗎? – user1333290 2012-04-16 00:55:37

+0

@ user1333290我們無法在不知道「uploadbutton」是什麼的情況下回答第二個問題。 – jbabey 2012-04-16 02:23:09

+0

.uploadbutton是給一個普通按鈕的類(input type ='button class ='uploadbutton') – user1333290 2012-04-16 02:31:11

相關問題