How do I disable all the onclick events on a page

北慕城南 提交于 2019-12-13 04:05:40

问题


Hi want to disable all onclick events on a page i write this:

window.onclick = anyfunction;
document.onclick=anyfunction;
function anyfunction() {};

That's work but if page contain this code

$("body").click(function () { 
  anyfunctions();
});

It will run. even i add

document.body.onclick

Jquery code runs again. I want to disable all onclick functions (java script and jquery and ... ) with javascript without using jquery library

Target is to block popup windows Thanks


回答1:


$("*").unbind("click"); // Removes all click handlers added by javascript from every element
$("[onclick]").removeAttr("onclick"); // Finds all elements with an 'onclick' attribute, and removes that attribute



回答2:


This css may help you in a better way.

function disableEvents()
{
$('#divname').css('pointer-events','none');
}

call this function where ever and whenever you would like to stop the click events on your page. This will work.




回答3:


you could also try

$('*').click(function(e){e.preventDefault();});

also see - How to prevent onclick statements from being executed?

and - Prevent onclick action with jQuery



来源:https://stackoverflow.com/questions/15801713/how-do-i-disable-all-the-onclick-events-on-a-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!