So, today I will show some useful codes that might be used for protecting information with Java Script.
1. First of all, the most common protection method is to disable the right-clicking, i.e. disallow user to copy stuff from a webpage.
/*
* This script is create by Artem Los
* Copyright (C) Artem Los, All rights reserved
* You may use this code in commercial and
* personal usage. You have no rights to
* sell this code.
* NOTE: Author must have credits for this code.
*/
var r = "True";
var text = "This site is protected!";
function IE(e) {
if (navigator.appName == "Microsoft Internet Explorer") {
if (event.button == "2" || event.button == "3") {
alert(text);
return false;
}
}
}
function NS(e) {
if (document.layers || document.getElementById && !document.all) {
if (e.which == "2" || e.which == "3") {
alert(text);
}
else if (e.which == "1") {
if (r == "True") { return false; }
}
}
return false;
}
document.onselectstart = new Function('if(r=="True"){return false;}');document.onmousedown = IE;document.onmouseup = NS;document.oncontextmenu = new Function("return false");
So, by using the code above you can be ensured that your information is safe at a basic level. It can still be taken by looking at the source, and copying it therefrom.
I will try to publish another code that actually protects the whole website, but remember that even though you got your page encrypted, it might still be cracked. Like with all kinds of protections, it is all about the time!
2. Another tip that I will talk about is links. It is so often that robots takes the, for instance, email address, and use it for spamming. However, we may solve this issue! Here I’ve got to methods that may help you to protect your links.
/*
* This script is create by Artem Los
* Copyright (C) Artem Los, All rights reserved
* You may use this code in commercial and
* personal usage. You have no rights to
* sell this code.
* NOTE: Author must have credits for this code.
*/
var AllLinks = new Array();
AllLinks[0] = "http://www.clizware.net/";
function email(x) {
if (x != "" || "undefined") {
window.location = AllLinks [x];
var a = document.getElementById("elink" + x);
}
else {
alert("This link does not exist!");
}
In the body of the page, enter:
<a href ="#" onclick ="email(0);" id="elink1">Link</a>
To improve this code, you can for example encrypt the link. I would recommend the escape/unescape function, but It actually does not matter. Once again, it’s all about the time.
The second method is not so useful, though. It is only working in Internet Explorer, and it have actually now function, just to hide the status bar.
/*
* This script is create by Artem Los
* Copyright (C) Artem Los, All rights reserved
* You may use this code in commercial and
* personal usage. You have no rights to
* sell this code.
* NOTE: Author must have credits for this code.
*/
window.defaultStatus = "All links are protected";