0

I display the image in my Rails app like this:

 = link_to image_tag(image.url), image_path(image.id)

I want to forbid the user to open this image in the new tab.

How do I achieve this?

Nadiya
  • 1,421
  • 4
  • 19
  • 34
  • do you wan't the user not to be able to do right click > open in new tab? maybe you can disable the right click menu (users would be able to open it knowing the url) or configure your webserver to require a referer to dispatch images, it's not something related to rails – arieljuod Aug 24 '18 at 12:28
  • Yes, that's a stock images app and the user should not be able to open an image without buying it. – Nadiya Aug 24 '18 at 12:58
  • I don't know how it works internally, but I could open it in new tab with a 'Cmd + click' instead of double click. – Jagdeep Singh Aug 24 '18 at 16:08

1 Answers1

1

You have multiple options:-

  1. Disable right click - but users can still get the url of the image through source file.

  2. Set the image as background of an HTML element - but it also has the same limitation as the first problem.

  3. Use image manipulation software such as imagemagik etc to redue size and quality of image.

  4. Add watermarks using image manipulation software like imagemagik.

How to use imagemagik

How to add water marks using imagemagik

There may be many more solutions

This answer is specific to your comment to address copyright issue.

For disabling right click see this page:- https://www.conceptinfoway.net/disable-right-click-on-particular-element-like-textbox-text-area/

Hussain Niazi
  • 579
  • 1
  • 3
  • 21