JavaScript hurries to the aid - 1
With development of a worldnet in its{her} users the set of remarkable opportunities has appeared. This from them is the free-of-charge hosting. To place the page in the Network as easy as shelling pears, in addition for 5 minutes, free-of-charge... But all readers know, where really there is a free-of-charge cheese: in exchange for services of accommodation of the information, on pages of a free-of-charge hosting banners khostera emerge. Also it is necessary to exist without convenience: as a rule, such services as SSI, Perl, PHP, SQL, as a rule, are absent. Only in the last time have started to appear khaljavnye SSI. And how to be that who began sajtostroenie in those days when the given services were present only on paid hostings? That at whom no even SSI. Given clause{article} also is called by him{it} to help.
And in what actually a problem? - uninitiated readers can be surprised. No, during first time all will be Ok. Pages which were created by hours, will be loaded on the server for few seconds. But when through completely not big time interval the quantity{amount} of pages on a site will reach{achieve} several tens and once again it is required to add new item{point} of the menu, or to change the address of the Web designer then you and nadoest to load all these HTML. Also will arise thinking: in fact a code of such elements as the menu, a cap, banners:) For often are present on each page at the constant form. And at the slightest change of one of elements (we shall say it is necessary to add new item{point} of the menu), it is necessary to edit everyone HTML a file, and the ambassador all this to load. And appears to place these repetitions in a separate file, to connect it{him} to each page, and simply making in him{it} changes to influence contents of all pages. In due time with this problem struggled about the help of frames. It was very convenient for web designers. And to visitors? Well, as will carry...
With occurrence SSI (Server Side Include - translation in a forehead: the Server Party{Side} of Connection) all has particularly changed. Makroinstrukii, executed on the server allowed to insert into the document the maintenance{contents} of other file. Thus, such elements as the menu were born{taken out} in a separate file and connected necessarily. Now changing the menu on unlimited quantity{amount} of pages, it was necessary to change one uniform file. Why SSI so quickly became popular? All is very simple: the document was generated on the party{side} of the server, and the user received ready result, at all not suspecting, that he "has been combined" in a single whole from several parts. All like would be adjusted. But not here that was. SSI was considered elitnym as service, except for that decently loaded the server. For this reason only in the last time SSI has appeared on free-of-charge hostings.
And as those who started for a long time. At whom the site has grown up. Who does not have means and desire for purchase of a paid hosting and a domain name. And in general, what to do{make} by that who does not want to move?
JavaScript - our old friend and the correct assistant comes to the aid. Due to the simplicity and improbable flexibility, JS much allows. Including connection of contents of separate files.
Inclusion of fragments of a code on JS in the document is carried out with the help tega <script>:
<script Language = "JavaScript" SRC = " a way to a file with JS a code ">
</script>
I shall not stop on interpretation tegov JS. Besides in my opinion, they are intuitively clear and simple in understanding.
" The way to a file with JS a code " specifies a way and a name of the file containing JS a code. The code contained in the specified file is connected to the document, and at the visitor the impression is created that the code contained in the connected file simply has been placed in the document. Thus at viewing a code of the document, the visitor will not see a code that contains in a connected file but only is higher the specified link to him{it} - the file will be loaded as separately. From the aforesaid the main difference of the given method from application SSI is visible. The page is going to not on the server, and on a computer of the user. But the user, certainly, also does not suspect about it.
Impatient readers to be surprised - as connection JS of a code from a file when it is necessary to connect HTML or at all the text can help? Without ceremony! In JS for an insert of a line in the document there is a command
document.write (' a line which is necessary for inserting into the document ');
Everything, that will be quoted '' simply inserted into the document. Thus, it is possible to insert into a file a design of type easy:
document.write (' <a href = " some link "> Link </a> ');
And henceforth change only one connected file to influence the maintenance{contents} of all site.
I want to notice only, that in a role of inverted commas it is possible to use both unary '' and double " ", but thus in contents a code there should be same inverted commas. In disgusting case before them it is necessary to put a sign, for example:
document.write (" <a href = " some link "> Link </a> ");
And a small example:
index.html
<html>
<head>
<title> JS SSI Demo </title>
</head>
<body>
<! - the Menu of a site->
<script Language = "JavaScript" SRC = "menu.js">
</script>
<! - the End of the menu of a site->
<! - Other maintenance{contents} of page...->
</body>
</html>
And a connected file:
menu.js
document.write (' <a href = " some menu link 1 "> Item{Point} of the menu 1 </a> ');
document.write (' <a href = " some menu link 2 "> Item{Point} of the menu 2 </a> ');
document.write (' <a href = " some menu link 3 "> Item{Point} of the menu 3 </a> ');
document.write (' <a href = " some menu link 4 "> Item{Point} of the menu 4 </a> ');
In result at opening a file index.html in him{it} contents menu.js will be substituted and in a window of a browser links which code is in menu.js will appear. Also I want to emphasize, that contents of a file menu.js will be substituted inside tega <script>, on semu a simple registration in a file <a href = " some menu link 1 "> Item{Point} of the menu 1 </a...> (without document.write ('');) will not give expected result.
Well, for today will suffice. Next time I shall tell to you about how dynamically to connect different files and to accept / pass parameters with one on other page.

|