readium-shared-js icon indicating copy to clipboard operation
readium-shared-js copied to clipboard

Hightlighting when selection is disabled because of DRM restrictions

Open jccr opened this issue 10 years ago • 4 comments

As stated in the title. This is for creating highlights when browser text selection is disabled to prevent copying & pasting.

(This was asked by someone else on today's call.)

jccr avatar Sep 22 '15 16:09 jccr

You can give this a try:

ReadiumSDK.reader.on(ReadiumSDK.Events.CONTENT_DOCUMENT_LOADED, function($iframe, spineItem) {
                var contentDoc = $iframe[0].contentDocument;
                var contentWindow = $iframe[0].contentWindow;
                contentDoc.body.oncopy =  function() { return false; }
                contentDoc.body.oncut =  function() { return false; }
                contentWindow.oncontextmenu = contentDoc.body.oncontextmenu = function(e) { 
                    e.preventDefault(); 
                    return false;
                }
});

It should work for all browsers. (IE8+ too)

jccr avatar Sep 22 '15 18:09 jccr

What about CSS user-select: none, and also touch-callout: none? `

danielweck avatar Sep 23 '15 15:09 danielweck

To give my code snippet more context:

This is how you could prevent copy-pasting while keeping selection intact.

jccr avatar Sep 24 '15 17:09 jccr

But you can still drag+drop, right? (just playing the devil's advocate, nit-picking :)

danielweck avatar Sep 24 '15 17:09 danielweck