Preventing Easy Image Download from my website

Hi,

I created a Backlight 3 website in 2020 (www.shillingphotojewelry.com). I did not realize until just now that a user could right click on any image and download to their computer. Is there a setting I can configure in Backlight to prevent the downloading options from displaying when the user right clicks on an image? I realize that a user could still take a screen shot but want to at least make it more difficult than right clicking and choosing download.
Thanks, Paul

There is no setting for that in Backlight.
You can, however, disable the entire right-click context menu using javascript via the scripts hook in phplugins.

Hi Rod,
Thanks for your quick response - However, there appears to be a way to control downloads as described in the docs. Maybe this is not relevant to the right click dropdown?

Please see below -

Image Downloads

Backlight’s albums, using the Pangolin Album template, may be configured to allow visitors to download your images.
Setup#

To set this up, go to Designer => Templates in the menu, then edit or create an album template using the Pangolin Album module.

Under the Advanced Setup control group, scroll down to the Downloads heading.

You will see a “Source” select with four options.
Disabled#

Correct. The image downloads feature is for when you want to provide downloads (either the existing photo rendition or a larger version or a different file type) and has nothing to do with the right-click context menu function of the browser.

1 Like

Can you provide the javascript code to do this? I have been trying to use

document.addEventListener('contextmenu', event => event.preventDefault());

in the scripts() function and keep getting syntax errors. Sorry for the newbie issues.

Can you post the entire code you’re using inside the scripts phplugins function, including the
function scripts()
part

// Disable right click menu
function scripts() {

document.addEventListener('contextmenu', event => event.preventDefault());

} // END /**/

I copied the samples file, changed the file name, and added just what you see above.

there are two ways of adding scripts in the scripts hook. One uses an echo' statement, the other does not.
There are sample functions in the phplugins file (make sure you’re using the phplugins-pangolin-sample.php file) that give examples.

If you use echo' then you’ll also need to escape all the single quotes in your code by preceded them with a backslash \

Thanks Rob! That got rid of the syntax errors but my bit of code did not disable the right click context menu. I guess I need to work on it a bit more.

Hi Charles,

After you get your code to disable the right click context dropdown menu would you be willing share it with me?
Thanks, Paul

Google around for some other code.
You are using the phplugins-pangolin-sample.php file as the starting point, correct?

If you’re still having problems, can you post a link to the site?

I just tried the code you used and it works. So there’s probably a simple error in your phplugins file. Perhaps your function is commented out in the file? (preceded by /* and followed by */)

Rod,

Thanks so much for all of the help. I’ve got it working now.

Paul,

Follow the instructions in the TTG documentation to use a custom PHP file. At the bottom of the file below the example functions (which are commented out) paste the following code

// Disable right click context menu
function scripts() {
    echo '
        <script>
             document.addEventListener(\'contextmenu\', event => event.preventDefault()); 
        </script>
    ';
} // END /**/

In the page template go to the advanced section and enable custom PHP selecting your custom file with the new code.

I have only tried this with the Safari browser and it works there. Let me know if you need more help.

Hi Charles,

I have Backlight 3. Do I need to upgrade to Backlight 4 to use the example PHP file to create a custom PHP file?
Thanks, paul

In my first response to your generous sharing of the code, I asked if I needed Backlight 4 because the location of the sample php file described in the instructions for using PHP plugins was not entirely correct.
Located here backlight/custom/phplugins not /backlight/modules/custom-resources/phplugins/phplugins-pangolin-sample.php. In the phplugins-pangolin-sample.php file there is a long list of example functions that do not appear to be commented out. Please see below. Thanks, Paul

[code removed by admin]

All the sample functions are commented out, so you don’t have to worry about that. Just make sure you are using the phplugins-pangolin-sample.php file to start with.

The location of the files changed between BL3 and BL4.

You can use the same code that Charles used.

Paul,

Just put the code after any of the sample functions that are commented out. The /* DELETE THIS LINE is the start of a commented out section and the // END /**/ is the end of a commented out section.

The location for the sample file given is for Backlight 4.