最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - enabling right click: <body oncontextmenu="return false"> - Stack Overflow

programmeradmin2浏览0评论

I've a web page(which I don't control) with:

<body oncontextmenu="return false">

I want to enable right click but there's no way I'm able to do it. In the saved html when I removed this oncontextmenu then it started working.

I've tried all mentioned here, but it's not working for me.

Here is the saved copy of web page.

I've a web page(which I don't control) with:

<body oncontextmenu="return false">

I want to enable right click but there's no way I'm able to do it. In the saved html when I removed this oncontextmenu then it started working.

I've tried all mentioned here, but it's not working for me.

Here is the saved copy of web page.

Share Improve this question edited May 23, 2017 at 12:34 CommunityBot 11 silver badge asked May 3, 2017 at 7:30 user5858user5858 1,2216 gold badges42 silver badges84 bronze badges 5
  • 2 Remove the oncontextmenu="return false" attribute...? – Rory McCrossan Commented May 3, 2017 at 7:31
  • I don't control the webpage – user5858 Commented May 3, 2017 at 7:32
  • Try this: stackoverflow.com/questions/1687790/… – Rory McCrossan Commented May 3, 2017 at 7:33
  • @RoryMcCrossan I've tried $("body").prop('onclick', null).off('click'); but does not work – user5858 Commented May 3, 2017 at 7:36
  • @user5858 If you don't control the web page then how you can enable the right click? This line oncontextmenu="return false" is clearly saying that you have intentionally disabled the right click. In order to enable the right click, you need to remove this attribute. – Arpit Kumar Commented May 3, 2017 at 7:48
Add a comment  | 

3 Answers 3

Reset to default 10

Try to execute the bellow code in webdev console :

window.addEventListener("contextmenu", 
  function(e){
     e.stopPropagation()
}, true);
body,html {
  width:100%;
  height:100%;
}
<body oncontextmenu="return false">
 text
</body>

In 2022 and for Firefox you must place the oncontextmenu attribut to the html tag not to the body tag

<html oncontextmenu="return false">
window.addEventListener('contextmenu', function(e) {e.stopPropagation();e.preventDefault();}, true);

in body & html

<html oncontextmenu="return false">
<body oncontextmenu="return false">

I hope it helps navigators.

发布评论

评论列表(0)

  1. 暂无评论