window.addEventListener("onbeforeunload",function() {return "are you sure?"});
^這似乎並沒有工作...在所有...該網頁將只需要關閉不顯示確認對話框......的addEventListener不onbeforeunload工作
我意識到......
window.onbeforeunload = function() {return "are you sure?"}
會工作,但我想添加到功能(例如添加許多事件監聽器到「onbeforeunload」函數),而不是完全重寫函數!
哦,lollllll,我知道這會是一些愚蠢的事 - ---非常感謝你! – zconnelly13
以下是addEvent的跨瀏覽器解決方案:'function addEvent(evt,fn,useCapture){if(this.addEventListener){this.addEventListener(evt,fn,useCapture); return true;} else if(this.attachEvent ){var r = this.attachEvent('on'+ evt,fn); return r;} else this ['on'+ evt] = fn;} Object.prototype.addEvent = addEvent;'(像這樣寫函數:object.addEvent(event,function,useCapture);)。 – Mageek
似乎不能在最新的FF - 14.0.1中工作 – Marcin