How to apply No right click script inhere...?

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: How to apply No right click script inhere...?

 
0
  #11
Apr 16th, 2008
You can't stop the right click action in a plain XML file. On some browsers, you can prevent the right click action in an HTML file, because an HTML file is allowed to run javascript, which is allowed to intercept the right click ( as you've surely discovered ). If you're displaying plain XML, you can't usually run javascript in the same frame.

However, if you don't mind learning XSLT, you can add a client-side XSL transform directive to the plain XML file, and have the transformation add javascript and alternate HTML rendering to the plain XML. In that way, you can get Javascript in the same frame as the XML. So in a given browser ( one that supports oncontextmenu ), you can stop the user getting a right-click menu in an XML file; if you don't mind learning/doing what I just suggested. ( Not all browsers support client side XSL, although IE6+ and Firefox 2+ certainly do ). Depending on how you want the XML displayed, that may not be appropriate.

You can't stop View Source, regardless! Even if you hide the toolbar of a frame using a popup/inner frame and successfully manage to disable right-click, there could be a hotkey bound to View Source, and blocking right-click only ever works with JS enabled, and on certain browsers. ( The Opera browser for e.g. makes it very easy to selectively ignore one page's Javascript temporarily, so it's not like a user has to go to any trouble to contravene any measure you may put in-place ).

The goodness of your intentions is wholly irrelevant, as is the class of your application. You're working with browsers, and browers quite reasonably limit what you're allowed to do through them.
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 1
Reputation: HTMLExpert is an unknown quantity at this point 
Solved Threads: 0
HTMLExpert HTMLExpert is offline Offline
Newbie Poster

Re: How to apply No right click script inhere...?

 
0
  #12
Mar 5th, 2009
Here ya go -- I selftought myself HTML --
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script language=JavaScript>
  2. <!--
  3.  
  4. var message=" 'YOUR SITE NAME' SAYS: SORRY YOU ARE NOT ALLOWED TO ACCESS ANY OPTIONS ON 'YOUR SITE NAME' . "
  5. function click(z) {
  6. if (document.all) {
  7. if (event.button == 2) {
  8. alert(message);
  9. return false;
  10. }
  11. }
  12. if (document.layers) {
  13. if (z.which == 3) {
  14. alert(message);
  15. return false;
  16. }
  17. }
  18. }
  19. if (document.layers) {
  20. document.captureEvents(Event.MOUSEDOWN);
  21. }
  22. document.onmousedown=click;
  23. // -->
  24. </script>
Last edited by HTMLExpert; Mar 5th, 2009 at 10:21 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC