在框架網(wǎng)頁(yè)中,通常使用src參數指定框架內的網(wǎng)頁(yè)地址,我們要做的就是,當直接打開(kāi)這個(gè)地址時(shí),讓它自動(dòng)監測然后再穿上外套,當然,首先要在網(wǎng)頁(yè)內添加檢測代碼,如下:
<script>
if(top.location==self.location)
{
top.location="index.htm?"+self.location;
}
</script>
就這么簡(jiǎn)單,注意,index.htm是外套網(wǎng)頁(yè)地址,接下來(lái)要做的就是,怎樣讓外套網(wǎng)頁(yè)自動(dòng)添加這部分內容,我們要在外套網(wǎng)頁(yè)中解析網(wǎng)頁(yè)地址,找到參數,然后將框架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框架,具體應用可在我的網(wǎng)站ggg82.126.com上看到。
聯(lián)系客服