亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何阻止或欺騙模糊事件偵聽器?

如何阻止或欺騙模糊事件偵聽器?

守候你守候我 2023-12-19 17:08:47
我已經編寫了一個小型 Web 控制臺腳本,該腳本可以在一個網站上運行,但似乎無法在另一個網站上運行。我想我真正想知道的是是否有更有效的方法來做到這一點。window.addEventListener("blur", function(event) {   event.stopPropagation();}, true);
查看完整描述

1 回答

?
搖曳的薔薇

TA貢獻1793條經驗 獲得超6個贊

直接在窗口上觸發的事件窗口沒有“捕獲階段”?”。

如果您查看事件調度和 DOM 事件流圖形,您可以看到該流程開始于?窗口,因此此類事件將已處于“目標階段”狀態。從第一步開始。

這意味著對于此類事件,capture?標志是無用的,因為所有事件偵聽器都將在“目標階段”,因為它們會在您的捕獲處理程序之前觸發。您無法停止將事件傳播到先前設置的處理程序”無論如何,所以

const phases_dict = {

? [Event.CAPTURING_PHASE]: 'Capturing Phase',

? [Event.AT_TARGET]: 'Target Phase',

? [Event.BUBBLING_PHASE]: 'Bubbling Phase'

};


// First listener defined without capturing flag, will fire first anyway

window.addEventListener( 'blur', evt => {

? const current_phase = phases_dict[ evt.eventPhase ];

? console.log( 'bubble blur is in', current_phase );

}, { capture: false } ); // fire at bubbling phase


// Second listener with capturing flag

window.addEventListener( 'blur', evt => {

? // This one will also capture the events on Elements in the Document

? // For our case, we only want the one on Window

? if( evt.currentTarget === evt.target ) {

? ? const current_phase = phases_dict[ evt.eventPhase ];

? ? console.log( 'capture blur is in', current_phase );

? }

}, { capture: true } ); // fire at capturing phase



// To show that bubbling events work as intended

// We also register click events

window.addEventListener( 'click', evt => {

? const current_phase = phases_dict[ evt.eventPhase ];

? console.log( 'bubble click is in', current_phase );

}, { capture: false } ); // fire at bubbling phase

window.addEventListener( 'click', evt => {

? const current_phase = phases_dict[ evt.eventPhase ];

? console.log( 'capture click is in', current_phase );

}, { capture: true } ); // fire at capturing phase

<pre>Click anywhere in this frame then click somewhere else in SO's page to trigger focus event</pre>


請注意,您可以停止 Elements 的傳播。?模糊事件,但不模糊Window事件。
您必須找到其他方法來阻止當前的偵聽器,也許是使用標志變量?



查看完整回答
反對 回復 2023-12-19
  • 1 回答
  • 0 關注
  • 125 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號