Disable right click on images

What would you like done?
I know this is ridiculous but my users are photographers and many of them are older folks and don’t understand how easy this is to bypass, so just go with me here.

I do not want to turn off pointer events because I still want the users to be able to zoom in to the full size image, and I don’t want to disable right click globally and reduce functionality.

I have tried this script for the thumbnail which only works when you refresh the page

<script type="text/javascript">
    $(document).ready(function(){
      $("img").bind("contextmenu",function(e){
        return false;
      });
    });
  </script>

Any creative ideas on how to get this working without losing functionality?

When do you need it done?
ASAP

What is your budget, in $ USD that you can offer for this task?
$100

3 Likes

The onPageChange event should help you:

It’s executed whenever the user navigates in Discourse. $(document).ready isn’t enough because Discourse normally avoids full page reloads.

Something like this could work for you:

<script type="text/discourse-plugin" version="0.8">
  api.onPageChange((url, title) => {
    $("img").bind("contextmenu",function(e) {
      return false;
    });
  });
</script>

This doesn’t handle posts that are inserted into the page by infinite scrolling, but maybe it’s enough to appease your users :slight_smile:

(I understand this is a marketplace post and you are looking for a fully baked solution. This isn’t that, but I thought it might still help.)

3 Likes

I think this was already answered elsewhere?

Yes, I’m not sure where the replies went, but I do not need this anymore.

Thank you @fefrei for chiming in.

This what I ultimately went with

<script type="text/discourse-plugin" version="0.8">

const TopicRoute = require("discourse/routes/topic").default;

TopicRoute.reopen({
	activate: function() {
		this._super();
		Em.run.next(function() {
		    $('body').on('contextmenu', '.cooked img, .mfp-img', function(e){ return false; });
		});
	}
});
</script>
8 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.