简体   繁体   中英

javascript onclick not firing or capturing event for some elements

I'm trying to capture the click events,
But for some elements the click event is not firing
Example search box and search button in Bing
I have tried injecting all the below code in Bing
it is capturing all the elements except the input searchbox and search button But the below code is working perfectly in google, yahoo searchbox and buttons

window.onclick=function(e){console.log(e)};
window.addEventListener("click",function(e){console.log(e)});
document.addEventListener("click",function(e){console.log(e)});

Please tell me why that is not being captured or fired and how to capture that element click

Inorder to capture the events the events should be captured through event capturing not via event bubbling.the useCapture flag is my culprit here.Set it to true and it solved my problem..
Bubble vs capture

window.addEventListener("click",function(e){console.log(e)},true);
document.addEventListener("click",function(e){console.log(e)},true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM