JavaScript技巧:让网页自动穿上外套
来源:岁月联盟
时间:2007-12-05
以下是引用片段:
<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>