0

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

Mojtaba
  • 41
  • 1
  • 1
  • 8
  • 1
    I don't think it is possible to achieve this – Arun P Johny Apr 04 '13 at 03:23
  • 1
    you need to write a lot of code to do this...my suggestion is to show transparent div to cover the whole page, but that will disable everything on your page – A.T. Apr 04 '13 at 03:50

3 Answers3

4
$("*").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
Impirator
  • 1,393
  • 1
  • 12
  • 24
3

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.

0

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

Community
  • 1
  • 1
lukeocom
  • 3,243
  • 3
  • 18
  • 30