Thursday, March 8, 2012

Disabled print option for SharePoint page


If you want to prevent user from printing SharePoint site page, you can use the below script in CEWB on your SharePoint site.


//Disabled File print and ctrl + P
<style type="text/css" media="print">
body { visibility: hidden; display: none }
</style>

The above JavaScript is not totally disabled the CTRL + P or Print option from browser File option. It tells the browser that if this Web page is set to print, switches the body to display nothing. Then, all that will print will be the standard header and/or footer that the browser appends to printed pages.  The user always get printed page with heading and blank page.

Disabled Right click, CTRL + A, C, V using JavaScript in SharePoint


You want user to avoid copy, Paste data from SharePoint site, use the below script in CEWB. It will prevent user to right click, and Copy, Paste data from SharePoint page

<script type="text/javascript">
    var message="Sorry, you do not have permission to right click.";

    function clickIE4(){
    if (event.button==2){
        alert(message);
        return false;
        }
    }

    function clickNS4(e){
        if (document.layers||document.getElementById&&!document.all){
            if (e.which==2||e.which==3){
                alert(message);
                return false;
                }
            }
        }
        if (document.layers){
            document.captureEvents(Event.MOUSEDOWN);
            document.onmousedown=clickNS4;
            }
        else if (document.all&&!document.getElementById){
            document.onmousedown=clickIE4;
        }
        document.oncontextmenu=new Function("alert(message);return false")
</script>

<script language="JavaScript1.2">

function disableselect(e){
return false
}

function reEnable(){
return true
}

//if IE4+
document.onselectstart=new Function ("return false")

//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
</script>

Auto Log Off after 10 min in SharePoint site


Some time users are required auto log off the SharePoint site after particular time for security. Here is JavaScript to add in CEWB on page.

You can set time in JavaScript and called the default Sign Out page of SharePoint. If you want to set auto log off for one particular page, set the below JavaScript function in CEWB on that page, otherwise for whole SharePoint site add the JavaScript function on master page.

<script type="text/javascript">
//Added for Auto LogOFF after 10 min


    function Timeout(){
        var t = setTimeout("RedirectToLogout()", 10*60000);
    }
    function RedirectToLogout(){
       var path = "http://YouSite/_layouts/SignOut.aspx";
       window.navigate(path);
    }
    </script>
<script>
  window.onload=Timeout;
</script>


Happy Coding