How To Prevent The Visitors From Printing Web Pages in Shopify
Do you want to prevent visitors from printing website content on your Shopify store? It’s easy. This article will guide you how to do that.
- From your Shopify admin, to to Online Store > Theme.
- Find the theme you want to edit and then click Action > Edit code.
- n the Layouts directory, click themes.liquid to open it in the online code editor.
- In the online code editor, add the below code before close </body> tag.1234567891011121314151617181920212223242526272829<script>scriptHuraTipsPreventPrinting = function($){$('body').append('<style type="text/css" media="print">body{visibility:hidden;display:none}</style>');$(document).on('keydown', function(e) {if(e.ctrlKey && (e.key == "p" || e.charCode == 16 || e.charCode == 112 || e.keyCode == 80) ){alert("Sorry, you are not authorized to take a Print");e.cancelBubble = true;e.preventDefault();e.stopImmediatePropagation();}});};var jqHuraTipsScript = document.createElement('script');jqHuraTipsScript.setAttribute("src", "https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js");jqHuraTipsScript.setAttribute("type", "text/javascript");if (jqHuraTipsScript.readyState) {jqHuraTipsScript.onreadystatechange = function () {if (this.readyState == 'loaded' || this.readyState == 'complete') {scriptHuraTipsPreventPrinting(jQuery.noConflict(true));}};} else {jqHuraTipsScript.onload = function () {scriptHuraTipsPreventPrinting(jQuery.noConflict(true));};}var d = document.getElementsByTagName("head")[0] || document.documentElement;d.appendChild(jqHuraTipsScript);</script>
- Click Save and you are done.
As soon as you install the script provided above, the visitors will can’t open the print option by shortcut key (Ctrl+P). If they still try the open print option from the properties menu and try print, they only get a blank page.
I hope it’s helpful to you.
Happy coding.
Thanks for this but I need also a code to prevent people from doing a print screen from any device by using hot keys or an app.