Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javascript to disable copy and print screen over ebook #274

Closed
mahag opened this issue Jan 28, 2015 · 1 comment
Closed

Javascript to disable copy and print screen over ebook #274

mahag opened this issue Jan 28, 2015 · 1 comment

Comments

@mahag
Copy link

mahag commented Jan 28, 2015

How can I prevent user to do control-c and control-a and print screen over index.html page when showing the book?
And for touch devices also to disable select / copy events?

Applying javascript and styling over index.html file doesnt work.It does not apply to book iframe .
style:
.b {
-webkit-user-select: none;
}

script:

     function Disable_Control_C() {
         var keystroke = String.fromCharCode(event.keyCode).toLowerCase();

         if (event.ctrlKey && (keystroke == 'c' || keystroke == 'a')) {
             event.returnValue = false; // disable Ctrl+C
         }
     }

$(document).ready(function () {
     $(window).keyup(function (e) {
         if (e.keyCode == 44) {
             $("body").hide();
         }

     });
 });

in index body <body class="chrome-app" onkeydown="javascript:Disable_Control_C()"

@danielweck
Copy link
Member

In my opinion, this question is not specific to Readium and should be asked on more general-purpose forums (such as StackOverflow?).

However, let me take this opportunity to share this tip: the Javascript snippet below explains how to inject "behaviours" (such as event interception) in each EPUB HTML Content Document that loads in the Readium views. Simply add to the head of index.html of the cloud reader:

<script type="text/javascript">

$(document).ready(function () {

ReadiumSDK.on(ReadiumSDK.Events.READER_INITIALIZED, function()
{
ReadiumSDK.reader.on(ReadiumSDK.Events.CONTENT_DOCUMENT_LOADED, function($iframe,s) 
{

var doc = $iframe[0].contentWindow.document;

//////////////////
// REPLACE THIS WITH DESIRED LOGIC
doc.addEventListener("contextmenu", function(e)
{
e.preventDefault();
}, false);
//////////////////

});         
}, this);
});

</script>

@mahag mahag closed this as completed Feb 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants