admin管理员组文章数量:1389772
I would like to disable view source shortcut key for IE using JavaScript. To disable Ctrl + C, I am using the following function:
function disableCopy() {
// current pressed key
var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();
if (event.ctrlKey && (pressedKey == "c")) {
// disable key press porcessing
event.returnValue = false;
}
}
Can any one suggest how to disable Alt + V + C bination?
I would like to disable view source shortcut key for IE using JavaScript. To disable Ctrl + C, I am using the following function:
function disableCopy() {
// current pressed key
var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();
if (event.ctrlKey && (pressedKey == "c")) {
// disable key press porcessing
event.returnValue = false;
}
}
Can any one suggest how to disable Alt + V + C bination?
Share Improve this question edited Feb 2, 2023 at 20:19 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jul 11, 2012 at 13:22 Vinod VutpalaVinod Vutpala 8533 gold badges11 silver badges17 bronze badges 9- 7 You realise this will not ultimately prevent people from viewing the source if they're determined, right? – Mitya Commented Jul 11, 2012 at 13:24
- 1 You want to disable viewing HTML source code? – Anuraj Commented Jul 11, 2012 at 13:24
- 1 Not sure why the downvote. The question may be flawed in concept, but for what it is, it's asked well enough and the OP shows a code attempt. +1. – Mitya Commented Jul 11, 2012 at 13:26
- 1 The web is open. If your page is good and people want to view your code then you should feel proud of yourself. If you're going to waste your energy preventing people from doing so then no one will bother reading through your code. It's not worth the hassle. – Aadit M Shah Commented Jul 11, 2012 at 13:27
- 6 This is an excellent way to make no one ever want to visit your webpage again. – jbabey Commented Jul 11, 2012 at 13:30
3 Answers
Reset to default 2Every browser has its built-in functionality to view the source code or the webpage. We can do one thing. That is disabling right click in your page.
For disable right click use the following code:
<SCRIPT TYPE="text/javascript">
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>
Remember one thing. We can view this source using firebug or some other third party tools. So we cant do this 100%.
You should not really prevent viewing code. Why?
Reasons
Eventually after all your efforts, if someone is determined he can still see your code.
You will defame your website by doing this.
You will kind-of behave like a "noob", as normally fellow developers see codes and they will break through your security measure by just disabling javascript.
There is no sensitive information in your code(I suppose) which can be used to pose a threat. But, if you have some code which can be used against the website you should really look into removing that code and making the website secure.
Disable binations
document.onkeydown = function(e) {
if (e.altKey && (e.keyCode === 67||e.keyCode === 86)) {//Alt+c, Alt+v will also be disabled sadly.
alert('not allowed');
}
return false;
};
Any ways, because I know how to do it, I will show you.
Here to disable right-click:
function clickIE() {if (document.all) {return false;}}
function clickNS(e) {if
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
document.oncontextmenu=new Function("return false")
alt + V + C is a very odd bination to have. Although following code will work, it's sort of hackish.
if (event.altKey) {
if (event.keyCode == 67 && window.prevKey == 86)
event.preventDefault();
else if (event.keyCode == 86 && window.prevKey == 67)
event.preventDefault();
window.prevKey = event.keyCode
}
本文标签: dom eventsHow to disable combination of keys using javascriptStack Overflow
版权声明:本文标题:dom events - How to disable combination of keys using javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744671284a2618839.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论