在框架網(wǎng)頁中,通常使用src參數(shù)指定框架內(nèi)的網(wǎng)頁地址,我們要做的就是,當(dāng)直接打開這個(gè)地址時(shí),讓它自動(dòng)監(jiān)測然后再穿上外套,當(dāng)然,首先要在網(wǎng)頁內(nèi)添加檢測代碼,如下:
<script>
if(top.location==self.location)
{
top.location="index.htm?"+self.location;
}
</script>
就這么簡單,注意,index.htm是外套網(wǎng)頁地址,接下來要做的就是,怎樣讓外套網(wǎng)頁自動(dòng)添加這部分內(nèi)容,我們要在外套網(wǎng)頁中解析網(wǎng)頁地址,找到參數(shù),然后將框架src參數(shù)指向該參數(shù)就行了,代碼如下:
<script>
document.write(‘<iframe id="mid" name="mid" width="100%"
height="100%" frameborder="0" scrolling="auto"‘)
var n=self.location.href.indexOf("?")//查看是否包含參數(shù)
if(n>0)//存在參數(shù)
{
//指向參數(shù)
document.write(" src="+self.location.href.substr(n+1))
}
document.write(‘></iframe>‘)
</script>
這里使用iframe框架,具體應(yīng)用可在我的網(wǎng)站ggg82.126.com上看到。
聯(lián)系客服