I have this script:
window.onload = function(){
document.getElementById('workspace').oncontextmenu = function(){
return false;
}
}
function click(e) {
if (navigator.appName == 'Netscape' && e.which == 3) {
window.location.reload();
return false;
else {
if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2)
window.location.reload();
return false;
}
return true;
}
document.onmousedown=click;
The workspace
is id of my <body>
element. Basically this script does is, it reloads the current page when right clicked on the page. I'm happy with it, this is all I want.
But this script is having a bug. The problem is the left click is disabled. I have some text on webpage but the you can select the text with this script enabled.
I have no much experience with JavaScript but I tried removing the last line of the script. When I did so the left click started working and I can select the text, but soon I noted that reload does not works.
It could be because of click function return false
in the third line. you need }
before else {
and need to wrap with {
}
for last if
block.
something like this should be ok.
function click(e) {
if (navigator.appName == 'Netscape' && e.which == 3) {
window.location.reload()
return false;
} else {
if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {
window.location.reload();
return false;
}
}
return 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.