当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 让网页自动穿上外套

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 让网页自动穿上外套


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-10   浏览: 254 ::
收藏到网摘: n/a

 

让网页自动穿上外套

进行网页设计时,许多网页都需要相同的边框图案和导航条,FrontPage给我们提供了共享边框方便设计,但是,这样也不太方便,毕竟每个网页都添加了相同的内容,无形中网页增大了,当然,对于动态网页,这不是问题,但是,如果是静态的呢?

怎样可以克服这个缺点,通过框架可以实现这些的,只是,框架又引来了另一个麻烦,就是如果直接打开框架内部网页,脱去了华丽的外套,是不是显得很单调,这里我们找一种好的方法,让脱去外套的网页自动穿上外套,你想到了吗?如果你对这个议题不感兴趣,你可以走开了,下面我们详细讨论。

在框架网页中,通常使用src参数指定框架内的网页地址,我们要做的就是,当直接打开这个地址时,让它自动监测然后再穿上外套,当然,首先要在网页内添加检测代码,如下:

<script>
if(top.location==self.location)
{
  top.location="index.htm?"+self.location;
}
</script>

就这么简单,注意,index.htm是外套网页地址,接下来要做的就是,怎样让外套网页自动添加这部分内容,我们要在外套网页中解析网页地址,找到参数,然后将框架src参数指向该参数就行了,代码如下:

<script>
document.write('<iframe id="mid" name="mid" width="100%" height="100%" frameborder="0" scrolling="auto"')
var n=self.location.href.indexOf("?")//查看是否包含参数
if(n>0)//存在参数
{
//指向参数
document.write(" src="+self.location.href.substr(n+1))
}
document.write('></iframe>')
</script>

这里使用iframe框架,具体应用可在我的网站ggg82.126.com上看到.

你可以打开该页的地址http://ggg82.go.nease.net/document/autotake.htm看一下效果,如有不懂的地方,也可以联系我。有什么好的看法,欢迎与我讨论.


"