[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

JavaScript - How do I disable printing my webpage?

Posted on 2011-02-21
14
Medium Priority
?
300 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
14 Comments
 
LVL 82

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 82

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 82

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 82

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 82

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 82

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 82

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

Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

Question has a verified solution.

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

CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Suggested Courses

650 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