2012-09-20 89 views
1

我正在爲Thunderbird編寫附加組件,並希望能夠在某些條件下取消發送電子郵件。我有以下代碼,它允許我在發送電子郵件之前執行代碼,但我不知道如何阻止它。停止發送電子郵件

document.getElementById("msgcomposeWindow").addEventListener("compose-send-message", function(){ 
    var msgcomposeWindow = document.getElementById("msgcomposeWindow"); 
    var msg_type = msgcomposeWindow.getAttribute("msgtype"); 

    // do not continue unless this is an actual send event 
    if(!(msg_type == nsIMsgCompDeliverMode.Now || msg_type == nsIMsgCompDeliverMode.Later)) 
     return; 


    alert('Sending Message...');//works fine 
    if(true){ //eventually this would have more logic... 
    //stop email 
    }else{ 
    //let email go 
    } 
}, true); 

我需要做些什麼來阻止電子郵件?

回答

4

爲了防止電子郵件被髮送你需要阻止事件冒泡:

function send_event_handler(evt) { 
    if(shouldStopEmail) { 
     evt.preventDefault(); 
     return false; 
    } 
} 

window.addEventListener("compose-send-message", send_event_handler, true); 
+0

這完美地工作。謝謝! – Daniel