?
Solved

JavaScript - How do I disable printing my webpage?

Posted on 2011-02-21
14
Medium Priority
?
301 Views
Last Modified: 2012-05-11
Hi,

I want users not to be able to print my page, not even ctrl A to select all then ctrl C to copy, cuz they can paste it later in Word and print!
0
Comment
Question by:feesu
  • 7
  • 7
14 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 34942481
0
 

Author Comment

by:feesu
ID: 34942558
Again leakim971, if the user is going to suffer to get this content, then let him suffer, but he won't get it easily.

You know, my page is going to be a set of Policies and Procedures that users should only read and not copy or download or even print. That's the whole idea.

Would you help me on achieving that? I don't mind if an expert interferes and compromise my page, as I know the users using my page are not of that type.
0
 
LVL 83

Expert Comment

by:leakim971
ID: 34942573
Yes I understand you, try this :
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>jQuery disable right click easily</title>
    <script language="javascript" type="text/javascript"
      src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
    </script>
    <script type="text/javascript" language="javascript">
        $(function() {
            $(this).bind("contextmenu copy cut paste", function(e) {
                e.preventDefault();
                alert("disabled!");
            });
        }); 
    </script>
</head>
<body>
    Sed lacus. Donec lectus. Nullam pretium nibh ut turpis.
    Nam bibendum. In nulla tortor, elementum vel, tempor at,
    varius non, purus. Mauris vitae nisl nec consectetuer.
    Donec ipsum. Proin imperdiet est. Phasellus dapibus semper
    urna. Pellentesque ornare, orci in consectetuer hendrerit,
    urna elit eleifend nunc, ut consectetuer nisl felis ac diam.
    Etiam non felis. Donec ut ante. In id eros.
</body>
</html>

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:feesu
ID: 34942602
Can't I also disable ctrl + A ?
0
 
LVL 83

Expert Comment

by:leakim971
ID: 34942633
Yes :


<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>jQuery disable right click easily</title>
    <script language="javascript" type="text/javascript"
      src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
    </script>
    <script type="text/javascript" language="javascript">
        $(function() {
            $(this).bind("contextmenu copy cut paste", function(e) {
                e.preventDefault();
                alert("disabled!");
            });
            $(this).keydown(function(e) {
							if(e.ctrlKey && e.keyCode == 65) {                         
                e.preventDefault();
                alert("disabled!");
							}
            });
        }); 
    </script>
</head>
<body>
    Sed lacus. Donec lectus. Nullam pretium nibh ut turpis.
    Nam bibendum. In nulla tortor, elementum vel, tempor at,
    varius non, purus. Mauris vitae nisl nec consectetuer.
    Donec ipsum. Proin imperdiet est. Phasellus dapibus semper
    urna. Pellentesque ornare, orci in consectetuer hendrerit,
    urna elit eleifend nunc, ut consectetuer nisl felis ac diam.
    Etiam non felis. Donec ut ante. In id eros.
</body>
</html>

Open in new window

0
 

Author Comment

by:feesu
ID: 34942687
Perfect, now if I wanted to prevent from highlighting and dragging the text into a Word file, do I use the <body ondragstart='return false' onselectstart='return false' >

Or does that have any gap or you recommend something else?
0
 
LVL 83

Expert Comment

by:leakim971
ID: 34942790
using : http://www.blograndom.com/blog/2009/07/jquery-plugin-to-disable-text-selection-on-elements/
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>jQuery disable right click easily</title>
    <script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
      <script language="javascript" src="http://code.jdempster.com/jQuery.DisableTextSelect/jquery.disable.text.select.js"></script>
    <script type="text/javascript" language="javascript">
        $(function() {
        
            $(this).bind("contextmenu copy cut paste", function(e) {
                e.preventDefault();
                alert("disabled!");
            });
            $(this).keydown(function(e) {
							if(e.ctrlKey && e.keyCode == 65) {                         
                e.preventDefault();
                alert("disabled!");
							}
            });

            $(this).disableTextSelect();
        }); 
    </script>
</head>
<body>
    Sed lacus. Donec lectus. Nullam pretium nibh ut turpis.
    Nam bibendum. In nulla tortor, elementum vel, tempor at,
    varius non, purus. Mauris vitae nisl nec consectetuer.
    Donec ipsum. Proin imperdiet est. Phasellus dapibus semper
    urna. Pellentesque ornare, orci in consectetuer hendrerit,
    urna elit eleifend nunc, ut consectetuer nisl felis ac diam.
    Etiam non felis. Donec ut ante. In id eros.
</body>
</html>

Open in new window

0
 

Author Comment

by:feesu
ID: 34942843
leakim971,

Disabling text select using the JQuery didn't work for Firefox, while the <body ondragstart='return false' onselectstart='return false' > thing did!

Try that in Firefox, it will allow you to select and drag to Word, but with the body thing, it will only allow Firefox to select but not drag, so that's better!
0
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 34942913
good, so just use both :
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>jQuery disable right click easily</title>
    <script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
      <script language="javascript" src="http://code.jdempster.com/jQuery.DisableTextSelect/jquery.disable.text.select.js"></script>
    <script type="text/javascript" language="javascript">
        $(function() {
        /*
            $(this).bind("contextmenu copy cut paste", function(e) {
                e.preventDefault();
                alert("disabled!");
            });
            $(this).keydown(function(e) {
							if(e.ctrlKey && e.keyCode == 65) {                         
                e.preventDefault();
                alert("disabled!");
							}
            });*/
            $(this).disableTextSelect();
        }); 
    </script>
</head>
<body ondragstart='return false' onselectstart='return false' >
    Sed lacus. Donec lectus. Nullam pretium nibh ut turpis.
    Nam bibendum. In nulla tortor, elementum vel, tempor at,
    varius non, purus. Mauris vitae nisl nec consectetuer.
    Donec ipsum. Proin imperdiet est. Phasellus dapibus semper
    urna. Pellentesque ornare, orci in consectetuer hendrerit,
    urna elit eleifend nunc, ut consectetuer nisl felis ac diam.
    Etiam non felis. Donec ut ante. In id eros.
</body>
</html>

Open in new window

0
 

Author Comment

by:feesu
ID: 34942931
- But do I still need the JQuery one if the other one works?
- Does JQuery help in preventing print-screen?
0
 
LVL 83

Assisted Solution

by:leakim971
leakim971 earned 2000 total points
ID: 34942995
>But do I still need the JQuery one if the other one works?

for the other events, browser compatibilty (when it apply) yes but you right it's big to disable something...

>Does JQuery help in preventing print-screen?

With keyboard yes with the browser menu I don't think
0
 

Author Comment

by:feesu
ID: 35062806
Perfect, give me sometime and I shall get back to you. Thanks!
0
 
LVL 83

Expert Comment

by:leakim971
ID: 35062815
np
0
 

Author Comment

by:feesu
ID: 35206433
I am sorry leakim971 for taking so much time on this, as the requirements of the management kept changing.
Thank you very much for you time and help!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month16 days, 5 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question