Reputation: 43
I am working on a php site.I want to use java script code for alert message when user click on anywhere in window.i am using window.onclick=function name()
function function name()
{
alert('message');
}
but it is not working.
Upvotes: 1
Views: 209
Reputation: 2509
document.onclick = clickMe;
function clickMe()
{
alert("clickMe");
}
window.onclick did not work when tested in IE8. So apparently the bottom line is that document.onclick is the preferred choice.
Upvotes: 1
Reputation: 9975
You're assigning the click handler wrong, try
window.onclick = name;
Upvotes: 2
Reputation: 12774
It has to be
function name()
{
alert('message');
}
and then you need to use window.onclick='name()';
Upvotes: 1
Reputation: 15861
function function name()
this line making issue. you declared function as twice. for this javascript is breaking.
use like this
function name()
{
alert('sds');
}
then assign function to the click handler like this.
window.onclick = name;
Upvotes: 1