SSRS viewer Right click
Can I suppresss right click on reports opened in SSRS viewer(Browser). If yes, then how?
October 14th, 2009 12:17am
Hi Virgo2008,
If I understand correctly, you want to disable Right-Click event on the report body.
Normally, we use JavaScript to disable Right-Click. So, in this case, to suppress Right-Click, we need to add JavaScript to the report, and use the JavaScript to suppress Right-Click.
Please follow these steps to know How to add JavaScript to a report, and then disable Right-Click:
1. Copy and paste the following JavaScript into a text file using Notepad
<!--
if (window.Event)
document.captureEvents(Event.MOUSEUP);
function nocontextmenu(){
event.cancelBubble = true
event.returnValue = false;
return false;
}
function norightclick(e){
if (window.Event){
if (e.which == 2 || e.which == 3)
return false;
}
else
if (event.button == 2 || event.button == 3){
event.cancelBubble = true
event.returnValue = false;
return false;
}
}
document.oncontextmenu = nocontextmenu; // for IE5+
document.onmousedown = norightclick; // for all others
//-->
2. Save the file with the name: SuppressRightClick.js
Please note to change the file extension from txt to js
3. Copy the file to <Install Driver>:\Program Files\Microsoft SQL Server\MSSQL.<X>\Reporting Services\ReportManager\Pages
4. Open the Report Project with Business Intelligence Development Studio
5. Open the report in the project.
6. In Layout mode, click the menu “Report” -- > “Report Properties…”
7. Go to “Code” tab, embed the following code:
'This code is used to register a JavaScript file reference to the report.
Public Shared Function AddJavaScriptFile()
System.Web.HttpContext.Current.Response.Write("<script src=""/Reports/pages/SuppressRightClick.js""></script>")
return nothing
End Function
8. Go to “Reference” tab, add “System.Web” referenece.
9. Deploy the report.
10. Now, while viewing the report in browser, we won’t be able to right-click on it.
Note: this solution is only used for only report. If we are going to disable Right-Click for all reports, we need to repeat step5 to step9 on each report.
If there is anything unclear, please feel free to ask.
Thanks,
Jin Chen
Jin Chen - MSFT
Free Windows Admin Tool Kit Click here and download it now
October 15th, 2009 10:41am
Thank you Jin.Can I embed javascript code directly into report instead of using .js file. Because .js file might need me to change our installation.
October 15th, 2009 8:51pm
Hi Virgo2008,Sure. We can.Please just replace "<script src=""/Reports/pages/SuppressRightClick.js""></script>" with the following JavaScript in the custom code.<!--if (window.Event)document.captureEvents(Event.MOUSEUP);function nocontextmenu(){event.cancelBubble = trueevent.returnValue = false;return false;}function norightclick(e){if (window.Event){ if (e.which == 2 || e.which == 3) return false;}else if (event.button == 2 || event.button == 3){ event.cancelBubble = true event.returnValue = false; return false; }}document.oncontextmenu = nocontextmenu; // for IE5+document.onmousedown = norightclick; // for all others//-->Thanks,Jin ChenJin Chen - MSFT
Free Windows Admin Tool Kit Click here and download it now
October 16th, 2009 4:17am
Thank you, I will implement it.
October 20th, 2009 8:29pm
Jim,thanks for the tip on how to supress the right click - I've been trying to add this code to my 2005 report (embedded in the code tab in the report preferences). However, I'm getting an error when I try to preview the report:Error 2 [rsCompilerErrorInCode] There is an error on line 0 of custom code: [BC30203] Identifier expected. \\us\corpdir\lco\confidential\information technology\collaborative applications\visual studio solutions\employeedirectory\employeedirectory\EmployeeDirectory.rdl 0 0 Warning 3 [rsCompilerErrorInCode] There is an error on line 3 of custom code: [BC42021] Function without an 'As' clause; return type of Object assumed. \\us\corpdir\lco\confidential\information technology\collaborative applications\visual studio solutions\employeedirectory\employeedirectory\EmployeeDirectory.rdl 0 0 I copied the code exactly as described - am I still missing something?Thanks,Anne
Free Windows Admin Tool Kit Click here and download it now
February 16th, 2010 5:42pm
Hi Anne,From this error "Function without an 'As' clause", I assume the error is caused by the custom code.Could you please paster the code you are using here?Please also try this:Public Shared Function AddJavaScriptFile() As String System.Web.HttpContext.Current.Response.Write("script here") return nothing End FunctionJin Chen - MSFT
February 17th, 2010 4:26am
Thanks Jin,
Sorry to be so long getting back to you on this - I've been off on another project but still need a way to supress the right click features in the report.
Here is the code I tried adding to the Code tab in the report preferences (I just cut it from your earlier post):
<!--if (window.Event)document.captureEvents(Event.MOUSEUP);function nocontextmenu(){event.cancelBubble = trueevent.returnValue = false;return false;}function norightclick(e){if (window.Event){ if (e.which == 2 || e.which == 3) return false;}else if (event.button == 2 || event.button == 3){ event.cancelBubble = true event.returnValue = false; return false; }}document.oncontextmenu = nocontextmenu; // for IE5+document.onmousedown = norightclick; // for all others//-->I also tried the function you noted above in instead of this code - it did not get an error but I did not see the text "script here" which I'm guessing it was to write out. I also tried some code from our Java developers that was supposed to capture the right click and notify the user that this feature was not available - it did not get an error but did not seem to work right either... here is their code:<script language="JavaScript1.2">
var clickmessage = "Downloading Image is disabled!";associateimages();
function associateimages() { for (i = 0; i < document.images.length; i++) { document.images[i].onmousedown = disableclick; }}
function disableclick(e) {
if (document.all) { if ((event.button == 2) || (event.button == 3)) { if (event.srcElement.tagName == "IMG") { alert(clickmessage); return false; } } } else if (document.layers) { if (e.which == 3) { alert(clickmessage); return false; } } else if (document.getElementById) { if ((e.which == 3) && (e.target.tagName == "IMG")) { alert(clickmessage); return false; } }}
</script>
Free Windows Admin Tool Kit Click here and download it now
March 8th, 2010 11:00pm
Hi Jin Chen,
I followed the above steps but still i am not able to disable right click.pls need help
Thanks
Suresh
December 7th, 2010 7:13am