iframe框架在IE瀏覽器下將白色背景設(shè)為透明色
發(fā)布時(shí)間:2014-06-13 10:27:08 作者:佚名
我要評(píng)論

使用iframe畫頁(yè)面的層級(jí)框架,大部分瀏覽器是沒(méi)有背景的,在IE中默認(rèn)是有一個(gè)白色的背景色的,為了顯示的更美觀一些將iframe中的allowTransparent屬性設(shè)置為true,即可
最近在做項(xiàng)目的過(guò)程中需要頻繁的使用iframe畫頁(yè)面的層級(jí)框架,大部分瀏覽器是沒(méi)有背景的,但是iframe在IE中默認(rèn)是有一個(gè)白色的背景色的,當(dāng)主背景色不是白色的時(shí)候,在這一部分會(huì)顯得很突兀。幫助手冊(cè)中給出了解決方案,即將iframe中的allowTransparent屬性設(shè)置為true,即可。在幫助文檔中也給出了相應(yīng)的示例,示例如下:
<BODY STYLE="background-color: red">
<IFRAME ID="Frame1" SRC="transparentBody.htm" allowTransparency="true">
</IFRAME>
<IFRAME ID="Frame2" SRC="transparentBody.htm" allowTransparency="true"
STYLE="background-color: green">
</IFRAME>
<IFRAME ID="Frame3" SRC="transparentBody.htm">
</IFRAME>
<IFRAME ID="Frame4" SRC="transparentBody.htm"
STYLE="background-color: green">
</IFRAME>
</BODY>
理論上,這樣做就沒(méi)問(wèn)題了,但是呢IE好像反應(yīng)不大,依舊還是有白色的背景。其實(shí)到了這一步,我們還需要在子頁(yè)面的<body>標(biāo)簽添加<body bgColor="transparent">,示例如下:
http://img.blog.csdn.net/20140610165850968?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQva3VucGVuZ19tdWJhbw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
main.html主頁(yè)面代碼:
<html>
<head>
<title></title>
</head>
<body style="background-color:blue;">
<table
style="width:100%;border:0;height:100%;cellpadding:0;cellspacing:0">
<tr height="100%">
<td height="100%" width="30%">
<iframe id="test1" src="test1.html" allowTransparency="true" width="100%" height="100%"></iframe></td>
<td height="100%" width="40%">
<iframe id="test2" src="test2.html" allowTransparency="true" width="100%" height="100%"></iframe></td>
<td height="100%" width="30%">
<iframe id="test3" src="test3.html" width="100%" height="100%"></iframe></td>
</tr>
</table>
</body>
</html>
test1.html頁(yè)面代碼:
<html>
<head>
<title></title>
</head>
<body bgcolor="transparent">
<h1>test1</h1>
</body>
</html>
test2.html頁(yè)面代碼:
<html>
<head>
<title></title>
</head>
<body>
<h1>test2</h1>
</body>
</html>
test3.html頁(yè)面代碼:
<html>
<head>
<title></title>
</head>
<body>
<h1>test3</h1>
</body>
</html>
這個(gè)小例子主要是iframe標(biāo)簽的allowTransparency屬性應(yīng)用,在該屬性設(shè)置為true并且iframe所加載的子頁(yè)面的<body>標(biāo)簽背景顏色設(shè)置為transparent(透明)時(shí),iframe將透明化。
allowTransparency設(shè)置或獲取對(duì)象是否可為透明。
bgColor 設(shè)置或獲取對(duì)象的背景顏色。
復(fù)制代碼
代碼如下:<BODY STYLE="background-color: red">
<IFRAME ID="Frame1" SRC="transparentBody.htm" allowTransparency="true">
</IFRAME>
<IFRAME ID="Frame2" SRC="transparentBody.htm" allowTransparency="true"
STYLE="background-color: green">
</IFRAME>
<IFRAME ID="Frame3" SRC="transparentBody.htm">
</IFRAME>
<IFRAME ID="Frame4" SRC="transparentBody.htm"
STYLE="background-color: green">
</IFRAME>
</BODY>
理論上,這樣做就沒(méi)問(wèn)題了,但是呢IE好像反應(yīng)不大,依舊還是有白色的背景。其實(shí)到了這一步,我們還需要在子頁(yè)面的<body>標(biāo)簽添加<body bgColor="transparent">,示例如下:
http://img.blog.csdn.net/20140610165850968?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQva3VucGVuZ19tdWJhbw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
main.html主頁(yè)面代碼:
復(fù)制代碼
代碼如下:<html>
<head>
<title></title>
</head>
<body style="background-color:blue;">
<table
style="width:100%;border:0;height:100%;cellpadding:0;cellspacing:0">
<tr height="100%">
<td height="100%" width="30%">
<iframe id="test1" src="test1.html" allowTransparency="true" width="100%" height="100%"></iframe></td>
<td height="100%" width="40%">
<iframe id="test2" src="test2.html" allowTransparency="true" width="100%" height="100%"></iframe></td>
<td height="100%" width="30%">
<iframe id="test3" src="test3.html" width="100%" height="100%"></iframe></td>
</tr>
</table>
</body>
</html>
test1.html頁(yè)面代碼:
復(fù)制代碼
代碼如下:<html>
<head>
<title></title>
</head>
<body bgcolor="transparent">
<h1>test1</h1>
</body>
</html>
test2.html頁(yè)面代碼:
復(fù)制代碼
代碼如下:<html>
<head>
<title></title>
</head>
<body>
<h1>test2</h1>
</body>
</html>
test3.html頁(yè)面代碼:
復(fù)制代碼
代碼如下:<html>
<head>
<title></title>
</head>
<body>
<h1>test3</h1>
</body>
</html>
這個(gè)小例子主要是iframe標(biāo)簽的allowTransparency屬性應(yīng)用,在該屬性設(shè)置為true并且iframe所加載的子頁(yè)面的<body>標(biāo)簽背景顏色設(shè)置為transparent(透明)時(shí),iframe將透明化。
allowTransparency設(shè)置或獲取對(duì)象是否可為透明。
bgColor 設(shè)置或獲取對(duì)象的背景顏色。
相關(guān)文章
- frame這個(gè)標(biāo)簽不知大家注意過(guò)沒(méi)有,它必須放在frameset中使用,而且經(jīng)常容易和iframe混淆,這里我們就來(lái)舉例講解HTML中iframe和frame的區(qū)別,需要的朋友可以參考下2016-05-30
深入剖析HTML5 內(nèi)聯(lián)框架iFrame
下面小編就為大家?guī)?lái)一篇深入剖析HTML5 內(nèi)聯(lián)框架iFrame。希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧,祝大家游戲愉快哦2016-05-04HTML中iFrame標(biāo)簽的兩個(gè)用法介紹
這篇文章主要介紹了HTML中iFrame標(biāo)簽的兩個(gè)用法,分別是作為彈出層鋪底覆蓋 ,和跨域?qū)懭隿ookie,需要的朋友可以參考下2015-07-09利用iframe在網(wǎng)頁(yè)中顯示天氣附效果截圖
這篇文章主要介紹了利用iframe在網(wǎng)頁(yè)中顯示天氣,這個(gè)功能還是比較實(shí)用的,實(shí)現(xiàn)起來(lái)也比較容易,需要的朋友可以看看2014-10-08- 這篇文章主要介紹了a標(biāo)簽的target鏈接指向iframe的方法,切記不是用Id來(lái)做指向的目標(biāo)而是name,需要的朋友可以參考下2014-09-04
用jquery進(jìn)行修復(fù)在iframe下的頁(yè)面錨點(diǎn)失效問(wèn)題
iframe頁(yè)面沒(méi)有滾動(dòng)條,在父窗體中出現(xiàn)滾動(dòng)條,錨點(diǎn)標(biāo)記就會(huì)失效,解決方法是用js計(jì)算iframe在父窗體位置,錨點(diǎn)在firame中的位置,兩者相加成為父窗體的滾動(dòng)2014-07-28iframe截取網(wǎng)站部分內(nèi)容實(shí)現(xiàn)思路及代碼
使用iframe可以截取網(wǎng)站的部分內(nèi)容,主要配合width、height、overflow等屬性來(lái)實(shí)現(xiàn)的,具體示例如下,需要的朋友不要錯(cuò)過(guò)2014-06-12淺談Iframe網(wǎng)頁(yè)內(nèi)部的導(dǎo)航窗口
下面小編就為大家?guī)?lái)一篇淺談Iframe網(wǎng)頁(yè)內(nèi)部的導(dǎo)航窗口。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-08-17