| | |
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
![]() |
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.
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..
•
•
Join Date: Mar 2009
Posts: 1
Reputation:
Solved Threads: 0
Here ya go -- I selftought myself HTML --
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script language=JavaScript> <!-- var message=" 'YOUR SITE NAME' SAYS: SORRY YOU ARE NOT ALLOWED TO ACCESS ANY OPTIONS ON 'YOUR SITE NAME' . " function click(z) { if (document.all) { if (event.button == 2) { alert(message); return false; } } if (document.layers) { if (z.which == 3) { alert(message); return false; } } } if (document.layers) { document.captureEvents(Event.MOUSEDOWN); } document.onmousedown=click; // --> </script>
Last edited by HTMLExpert; Mar 5th, 2009 at 10:21 am.
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Editing client side registry
- Next Thread: Displaying all object properties
| Thread Tools | Search this Thread |
ajax ajaxexample ajaxjspservlets array browser bug captcha captchaformproblem cart checkbox child class close codes cookies createrange() cursor date debugger dependent disablefirebug dom dropdown editor element embed engine enter events explorer ext file firefox focus form forms frameworks getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe images internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl maps masterpage math matrixcaptcha media menu object onerror onmouseoutdivproblem onreadystatechange parent paypal pdf php position post programming progressbar prototype rated redirect runtime safari scale scriptlets scroll search security session shopping size software star stars synchronous toggle unicode variables web webservice wysiwyg \n






