Bloquear el botón derecho en tu web para las imágenes y mostrar un men – jonytips.com
Ir directamente al contenido

Shopify Expert

LOS MEJORES RECURSOS PARA TU ECOMMERCE

Bloquear el botón derecho en tu web para las imágenes y mostrar un mensaje

Bloquear el botón derecho en tu web para las imágenes y mostrar un mensaje

Vamos a copiar todo este código y pegarlo en el theme.liquid de nuestra plantilla. Para pegar el código tiene que ser al final de nuestra plantilla pero antes de que termine el comando <body>

Está demostrado que deshabilitar el botón derecho del mouse en las páginas web solo trae causas negativas. Este código en particular actúa sólo sobre las imágenes y es para dar un mensaje (además de no dejar en una primera instancia copiar o guardar la imagen) lamentablemente siempre será posible que con el inspector de elementos u otros comando guardar el elemento, pero se lo podemos hacer un poco más difícil.

Peguen este código en entre los dos <head> de su theme.liquid

{{ «no-mouse-imagenes.js» | asset_url | script_tag }}

Luego en la carpeta de assets del editor de código crean un archivo nuevo y lo llaman no-mouse-imagenes y eligen .js y pegan este texto que agregó a continuación.

 

Si se te hace muy difícil puedes encontrar este Jony Tips en Productos > complementos

function disableClick(e) {
    var message = 'WOULD YOU STEAL A CAR?';
    if (document.all) {
        if (((event.button == 2) || (event.button == 3)) && ((event.srcElement.tagName == "IMG") || (event.srcElement.getAttribute("type").toUpperCase() == "IMAGE"))) {
            if (event.srcElement.oncontextmenu) {
                event.srcElement.oncontextmenu = function(event) {
                    if (event.preventDefault) {
                        event.preventDefault();
                    };
                    if (event.stopPropagation) {
                        event.stopPropagation();
                    };
                    if (event.returnValue) {
                        event.returnValue = false;
                    };
                };
            } else {

                if (event.srcElement.addEventListener) {
                    event.srcElement.addEventListener("contextmenu", function(event) {
                            if (event.preventDefault) {
                                event.preventDefault();
                            };
                            if (event.stopPropagation) {
                                event.stopPropagation();
                            };
                            if (event.returnValue) {
                                event.returnValue = false;
                            };
                        }

                    );
                } else if (event.srcElement.attachEvent) {
                    event.srcElement.attachEvent("contextmenu", function(event) {
                            if (event.preventDefault) {
                                event.preventDefault();
                            };
                            if (event.stopPropagation) {
                                event.stopPropagation();
                            };
                            if (event.returnValue) {
                                event.returnValue = false;
                            };
                        }

                    );
                };

            };

            alert(message);
            return false;
        };
    } else if (document.layers)

    {
        if ((e.which == 2) || (e.which == 3)) {

            if (e.target.oncontextmenu) {
                e.target.oncontextmenu = function(e) {
                    if (e.preventDefault) {
                        e.preventDefault();
                    };
                    if (e.stopPropagation) {
                        e.stopPropagation();
                    };
                    if (e.returnValue) {
                        e.returnValue = false;
                    };
                };
            } else {

                if (e.target.addEventListener) {
                    e.target.addEventListener("contextmenu", function(e) {
                            if (e.preventDefault) {
                                e.preventDefault();
                            };
                            if (e.stopPropagation) {
                                e.stopPropagation();
                            };
                            if (e.returnValue) {
                                e.returnValue = false;
                            };
                        }

                    );
                };


            };


            alert(message);
            return false;
        };
    } else if (document.getElementById)

    {
        if (((e.which == 2) || (e.which == 3)) && ((e.target.tagName == "IMG") || (e.target.getAttribute("type") && e.target.getAttribute("type").toUpperCase() == "IMAGE"))) {

            if (e.target.oncontextmenu) {
                e.target.oncontextmenu = function(e) {
                    if (e.preventDefault) {
                        e.preventDefault();
                    };
                    if (e.stopPropagation) {
                        e.stopPropagation();
                    };
                    if (e.returnValue) {
                        e.returnValue = false;
                    };
                };
            } else {

                if (e.target.addEventListener) {
                    e.target.addEventListener("contextmenu", function(e) {
                            if (e.preventDefault) {
                                e.preventDefault();
                            };
                            if (e.stopPropagation) {
                                e.stopPropagation();
                            };
                            if (e.returnValue) {
                                e.returnValue = false;
                            };
                        }

                    );
                };


            };


            alert(message);
            return false;

        };
    };

};

function associateImages() {
    for (i = 0; i < document.images.length; i++) {
        document.images[i].onmousedown = disableClick;
    };

};

if (document.all) {
    if (document.onmouseup) {
        document.onmouseup = disableClick;
    } else {
        window.onmouseup = disableClick;
    };

} else if (document.getElementById) {
    if (document.onmousedown) {
        document.onmousedown = disableClick;
    } else {
        window.onmousedown = disableClick;
    };

} else if (document.layers) {
    associateImages();
};

Dejar un comentario

Por favor tenga en cuenta que los comentarios deben ser aprobados antes de ser publicados