
Small cunnings JavaScript
Reached{Achieved} of a high degree of an enlightenment of the guru of web - mastering can rest on laurels deservedly, prosecute extremely architectural subjects of designing of sites, and, maybe, sometimes to allow consultations for very big money. But to begin such gurus, years of spiritual perfection are required. And who knows, that it is more complex - to comprehend{overtake} for the neophyte as the clap{cotton} of one palm sounds, or to understand features of functioning of object StyleSheet in objective model JavaScript...
The certificate{act} the first. The form and the maintenance{contents}
As is known, cascade tables of styles CSS are one of the most progressive inventions of mankind (after analginum). Utility of them consists that now there is no necessity to build various design shifts directly in a HTML-code, littering thus natural grace of his designs variegated attributes of color, the size and a site. There is a way better - to reduce the description of style in one table of styles and to connect her as required. We shall remind, that it is done{made} by a premise{room} in heading of the HTML-document of a line approximately the following maintenance{contents}:
<link rel = "stylesheet" type = "text/css" id = "css1"
title = "Default" href = "/css/default.css ">
As web designer are the essences, suffering chronic surplus of optimism, they often believe, that the style marking specified in a file default.css, in a status to satisfy all visitors of their remarkable site. However the world is much more severe, than the person of any trade, though somehow connected with creativity assumes. Does not pass also one thousand visitings as in a mail box of the web designer numerous requests « slightly start to be dumped to change design ». When polite, and when also excessively spiteful and with threats of physical violence. And any changes in design not only will not correct, but even will worsen position therefore as always there will be people it was pleasant which more earlier.
What to do{make}? Many will follow to advice{council} mentioned in the beginning of clause{article} of the guru and these requests will ignore. But, not having comprehended{overtaken} the Shadow, it is impossible to see Light - and we shall show how all the same to enable the user easy movement of a mousy to receive design arranging{suiting} it.
So, suppose, that you, as well as the author of this clause{article}, prefer to see the black text on a white background. And, accordingly, register in default.css the following definition:
body {background-color: white; color: black}
But couple of days back to you the angry note from the visitor of a site V.V.Pupkin who wishes to see on a site the white text on a black background has acted{arrived}. As Pupkin - the person known and dear, you cannot give up to him in this small request for what create the alternative table of styles pupkin.css:
body {background-color: black; color: white}
Now it are necessary to make so that Pupkin and his supporters saw a site such as it is pleasant to them, and other visitors - such as it is pleasant to you. For this purpose it is necessary to realize JavaScript-function of dynamic replacement of the table of styles:
<script language = "javascript">
function changeCSS (name) {
// Pay attention - the identifier of a collection
// "styleSheets" it is sensitive to the register:
document.styleSheets ['css1'] .href = '/css / ' + name +
.css ';
}
</script>
It are necessary to add in a code of page elements of management which will allow to change the table of styles. We admit{allow}, it will be buttons « the Standard version » and « the Version for V.Pupkin »:
<button onclick = " changeCSS (' default ') ">
The standard version
<button onclick = " changeCSS (' pupkin ') ">
The version for V.Pupkin
Enjoy.
The certificate{act} of the second. Secret and obvious
Usil`em the stranger
To not help
[Till time] to reveal
Gentle
To bud of a chrysanthemum.
From the collection of the unknown Samurai
After achievement by the author certain{determined} (not the maximum{supreme}!) stages of self-improvement at him the persevering desire to hide fruits of the ingenious inspirations from persevering hands worth by a level below imitators is shown. But how to make it if in any window of a browser it is enough to allocate a slice of the text, to copy it in the buffer - and will not pass also minute how desired svezheukradennaja the information will appear on a site of the competitor? Provided that the competitor is not the user technically advanced (that obviously, otherwise he, probably, would not began to resort to plagiarism), there is a number{line} of the certain methods capable to no small degree to complicate to him this impartial employment{occupation}. The experienced user, certainly, will bypass all these shifts in some minutes.
First, we shall forbid to the user to allocate the text (as well as something another). It is trivial enough problem which is solved one small fragment of a JavaScript-code in section HEAD:
<script language = "javascript">
<!--
// We establish{install} a periodic call of function
// dropSelection with an interval 5 ms
window.setInterval (" dropSelection () ", 5);
function dropSelection () {
// We dump{reset} allocation of any part of the document
document.selection.empty ();
}
//->
</script>
Second, we shall clean{remove} an opportunity in general to use the right button of a mousy. In fact with its{her} help it is possible to make a lot of harmful, for example to save liked a picture on a disk. It hardly is more complex , but too does not represent anything extraordinary:
<script language = "javascript">
<!--
function right (e) {
// If the right or average button of a mousy is pressed
if (event.button == 2 || event.button == 3) {
alert (" the Right button of a mousy is switched - off! ");
return false;
}
return true;
}
// We establish{install} function right () in quality obrabotchika
// Events of pressing of the button of a mousy
document.onmousedown=right;
document.onmouseup=right;
//->
</script>
And at last, the main thing. Described further ehzotericheskaja the technics{technical equipment} can have many harmful consequences including for karmy using, therefore its{her} essence of the guru of web - mastering pass the pupils only at the closing stages of training, and even at all leave at itself.
Let's break each static document contained on a site, into two parts. The first them them will be a pattern of the document (for example, index.html), comprising headings, elements of registration and the other useless information given to the user in loading. The pattern can look approximately as follows:
<html>
<head>
<title> V.V.Pupkin's Home page </title>
</head>
<body>
<h1> V.V.Pupkin's Home page </h1>
<script language = "javascript" src = "index.js">
</body>
</html>
Pay attention to the selected line. Yes, you are completely right - the maintenance{contents} of a script in this case is loaded from an external source, and in him there can be everything, everything. In this case the script contains that helpful information which the marked V.V.Pupkin does not want so to give simply to simple users for copying and plagiarism. She is deduced in a browser in the most simple way: with the help of a method document.write (). An example of a file index.js:
document.write (' <p> this paragraph contains the information, ' +
' Protected <i> the strict copyright </i>, ' +
' And demanding careful judgement. </p> '); And now attention, a question: what will the user who has chosen in the menu of the liked browser item{point} View Source see? Absolutely correctly - only contents of a file of a pattern index.html! Everything, that is in index.js, remain outside his attention. Certainly, nobody will prevent the user to type{collect} in a line of a browser something like www.pupkin.com/index.js, but it is rather unreliable way - « never know, how bees » will react. Besides even more to complicate to the user a life, it is meaningful to introduce in a script function of any primitive encryption (in general, will suffice at all encryption, and, for example, reversirovanija that it was impossible to copy fragments of the text in the buffer). It will approximately look so:
copyrightedText =
"> p / <motjaripok mishjazhorts nehhihhaz tsket totEH> p <";
function reverse (text) {
resultText = new String;
for (i = 0; i <text.length; i ++) {
resultText = resultText +
text.charAt (text.length - i);
}
return resultText;
}
document.write (reverse (copyrightedText));
This fragment of a code will give out in a browser the text « <p> This text is protected by the strict copyright </p> ». To restore the text, the user should write the special program, that is to spend approximately as much efforts, how much and to the web designer. And if the user does not suffer excessive mazokhizmom, he simply will go to search for this information in the other place.
As preparation of the information for the publication at such circuit - process inconvenient enough, usually similar "encryption" occurs on the party of the server. However, using language Perl, it is possible to write in some minutes the program, in a batch mode resulting{bringing} all site entirely to conformity with the new doctrine. As this clause{article} is devoted JavaScript, instead of Perl, we shall not stop in detail on this question.
Unfortunately or fortunately, tricks with an interdiction to allocate the text and to use the right button of a mousy do not work in the browsers based on Mozilla (including in Netscape 6). Search of decisions for them we shall leave as the domestic task. However, if time does not suffer{bear} also terms draw in, the author can be called to account to the address, specified in the signature.
Also remember, true gurus of web - mastering do not use these receptions. Because they have nothing to hide, and « svetel their face ». And if who will manage on nevezhestvu to use fruits of their works in the mercenary purposes there will be him an all-round public reprimand. And addresses of their resources will be forever brought in shameful lists of the guru (as those on the sites they often get{start} section "Clones").