天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

在html頁面中包含共享頁面的方法

How do I include one HTML file inside another?
It's very common practice to have a consistent theme on a web site. You might have a standard navigation bar or a logo or even just a page footer with copyright and administrative information. Rather than actually having that information on each and every page it would certainly be nice if you could write your navigation bar once, keep it in one file, and then reference that file in each of several different pages. Make a change to the navigation bar in one place and instantly all pages are updated.
Welcome to "include" files - an incredibly powerful facility that can do this, and so much more, on your web site.

Includes break down into two categories: client and server. A "client" side include is one performed by your browser. Unfortunately, there is no specific syntax in HTML for client side includes so we have to play a small game using Javascript. A "server" side include is exactly that - the include happens on your web server so the client browser never even knows it happened.
Server Side Includes
We'll start with the conceptually easier one: the server side include. The specific syntax will vary based on what type of server you have and what your pages are written in.
Simple HTML pages on most common web servers can use a syntax called Server Side Include, or SSI. As an example in an HTML file a.html we can place this line:
<!--#include FILE="b.inc" -->
The page seen by a browser viewing a.html will consist of the contents of a.html before the include line, followed by the contents of b.inc, followed by the contents of a.html after the include line. Put the HTML for your navigation bar in a file like b.inc, and all your pages can show the exact same bar.
SSI is available on both Apache and Microsoft IIS web servers. On Apache some configuration may be needed but even if you don't have access to the actual server configuration files it can typically also be enabled by commands in a file named .htaccess that you will either find or can create in your server's web directory. Read more about Apache SSI here. Under IIS, SSI is enabled anytime you use ".ASP" pages -- so the only configuration you need do is to name your pages .ASP instead of .html. Read more about Server Side Include in ASP pages here.
Another popular ASP-like programming environment is php. php's include syntax is very simple:
<? readfile("b.inc"); ?>
Naturally, php has a host of additional processing ability but much like ASP the only requirement to make the include above work is to have php on your web server and name your file ".php".
With all of the above approaches, the browser viewing the page knows absolutely nothing about the include - it all happened before the page was downloaded. However, sometimes processing an include on the server isn't the right option. That's where processing an include on the client comes in.
Client Side Includes
As I mentioned above, there is no actual syntax for a client-side include but we can mimic one using Javascript. For example:
<script src="b.js" type="text/Javascript"> </script>
When encountered the browser downloads the script "b.js", executes it, and prints any output that the script might generate as if it were inline HTML. Technically that's not an include but the script "b.js" could be nothing more than a series of Javascript "print" statements such as these:
document.write("<table>")
document.write("<tr>")
... and so on
You can see it's "printing" the HTML you want included. In other words, if you can format your include file as a series of Javascript prints, you can use client-side include to insert it.
Now things can get very interesting, because we'll introduce two things: remote includes, and CGI programs, into the mix.
Remote Includes
The files we've included so far have been assumed to be on your own server in the same location as your other HTML pages. In almost all cases you can "include" using a full URL to any other server on the interNET.
For client-side includes it's very simple. It just works:
<script src="http://example.com/b.js" type="text/Javascript"> </script>
This works just like the earlier example execpt that b.js will get loaded from example.com rather than your own server. Similarly, php also "just works":
<? readfile("http://example.com/b.inc"); ?>
Unfortunately Apache SSI directives do not support remote includes. But there's almost always a way and we have a workaround using CGI.
CGI Includes
So far we've included only "static" HTML pages. As it turns out you can "include" the output of a server-run CGI program. This then becomes our solution for Apache's lack of support for remote includes. We'll start with this very short Perl program:
use LWP::Simple;
print "Content-type:text/html/n/n";
getprint ($ENV{'QUERY_STRING'});
We'll call it "proxy.pl". Proxy.pl must be appropriately installed on your server into your cgi-bin directory or its equivalent. By being local to your server Include directives can reference it.
Proxy.pl simply fetches the contents of URL passed as a parameter. This means we can perform an apache remote include this way:
<!--#include VIRTUAL="/cgi-bin/proxy.pl?http://example.com/b.inc" -->
It works like this:
The include executes proxy.pl with the parameter "http://example.com/b.inc"
Proxy.pl then fetches b.inc from example.com and prints it.
The result is that the contents of b.inc show up as an included file.
Includes + remote includes + CGI
So far we've used a CGI program to fetch what is essentially just another static html file. In fact, if we put all these pieces together we can create some very useful and interesting interNET applications.
Randy Cassingham of This is True wanted to be able to provide his readers who had web sites the ability to host one of his stories. Sounds like a job for an include file, right? But he also wanted that story to change every day. That's more than a static HTML page; that's a CGI program that outputs a different story each day.
The result is tad.pl (True-A-Day) - a Perl script that picks a new story every day and outputs HTML. Given what we've talked about so far so you can probably guess how it's used. As a client side include:
<script src="http://www.thisistrue.NET/cgi-bin/tad.pl" type="text/Javascript"> </script>
That's it in its simplest form. Note that:
tad.pl is written in Perl. It does whatever it needs to gather the HTML for the story to be output.
tad.pl outputs Javascript. In fact, tad.pl's output is nothing more than a series of "document.write" statements.
The client browser executes the Javascript. The result is that it prints the HTML that tad.pl constructed for today's story.
Using tad.pl in a server-side include looks like this:
<!--#include VIRTUAL="/cgi-bin/proxy.pl?http://www.thisistrue.NET/cgi-bin/tad.pl?ssi=1" -->
Note that as discussed above we had to use a local CGI program, proxy.pl, to fetch the remote URL.
Note also that we've added an additional parameter, ssi=1. This causes tad.pl to output the HTML it gathers without the Javascript document.write statements. The final sequence looks like this:
proxy.pl executes on your server, and is passed the URL "http://www.thisistrue.NET/cgi-bin/tad.pl?ssi=1".
proxy.pl fetches that URL, causing tad.pl to execute on www.thisistrue.NET.
tad.pl once again does whatever it needs to gather the HTML for the story to be output.
tad.pl outputs the HTML to be included.
That output is returned to proxy.pl, which in turn prints it, where it becomes the "included text".
The client browser sees nothing but HTML - the HTML from the containing page with the HTML from tad.pl inserted in place of the include statement.
As you can see, includes are not only a great organizational tool allowing you to collect common information into fewer files, but also a powerful way to add functionality to your web site and perhaps others. I'll end this with True-A-Day included via a client side include:

JavaScript技術(shù)在html頁面中包含共享頁面的方法,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 男女久久久国产一区二区三区 | 双性将军粗壮H灌满怀孕 | 7723日本高清完整版在线观看 | 最近免费中文字幕MV在线视频3 | 日本工口生肉全彩大全 | 国产高清视频青青青在线 | 欧美高清69vivo | 国产欧美一区二区精品性色tv | 欧美九十老太另类 | 成人小视频免费在线观看 | 国内卡一卡二卡三免费网站 | 日韩欧美视频一区二区 | 中文字幕无线观看不卡网站 | 日韩亚洲欧美中文在线 | 精品国产免费第一区二区 | 久久伊人天堂视频网 | 日产精品久久久久久久蜜殿 | 草莓视频免费在线观看 | 久久中文字幕无线观看 | 一本久道久久综合狠狠躁AV | 亚洲欧美另类无码专区 | 人妻系列合集 | 国产精品悠悠久久人妻精品 | 亚洲.欧美.中文字幕在线观看 | 特黄AAAAAAA片免费视频 | 三级在线观看网站 | 久久精品嫩草影院免费看 | 国内久久久久影院精品 | 无码成A毛片免费 | 人人艹人人 | 日韩a在线看免费观看视频 日韩a视频在线观看 | 无人影院在线播放视频 | 青柠电影在线看 | 噜噜噜在线AV免费观看看 | 精品国产在线国语视频 | 国产成人亚洲精品午夜国产馆 | free性中国hd护士高清 | 国产精品久久久久无码AV色戒 | 亚洲精品无码AV中文字幕蜜桃 | 女神被调教成了精盆 | 无限资源在线观看完整版免费下载 |