PNG format image files are not very compatible with browsers, but such transparent PNG files can also be used as virtual edges, and are becoming more and more popular in design. Especially in IE6, there are many bugs and poor support, but there is no way to have a large number of users. We should first consider the support for it. FF supports PNG images, and IE7 also supports PNG images.
There is a simple way to solve the PNG compatibility problem of IE6 and FF on the Internet, and a piece of js code can be done. The Code is as follows. We recommend that you save this code as an independent JS file for convenient page calling. Function correctpng ()
{
For (VAR I = 0; I <document. Images. length; I ++)
{
VaR IMG = Document. Images [I]
VaR imgname = IMG. SRC. touppercase ()
If (imgname. substring (imgname. Length-3, imgname. Length) = "PNG ")
{
VaR imgid = (IMG. ID )? "Id = '" + IMG. ID + "'":""
VaR imgclass = (IMG. classname )? "Class = '" + IMG. classname + "'":""
VaR imgtitle = (IMG. Title )? "Title = '" + IMG. Title + "'": "Title = '" + IMG. Alt + "'"
VaR imgstyle = "display: inline-block;" + img.style.css text
If (IMG. align = "Left") imgstyle = "float: Left;" + imgstyle
If (IMG. align = "right") imgstyle = "float: right;" + imgstyle
If (IMG. parentelement. href) imgstyle = "cursor: hand;" + imgstyle
VaR strnewhtml = "<span" + imgid + imgclass + imgtitle
+ "Style = \" "+" width: "+ IMG. Width +" PX; Height: "+ IMG. height +" PX; "+ imgstyle + ";"
+ "Filter: progid: DXImageTransform. Microsoft. alphaimageloader"
+ "(Src = \ '" + IMG. SRC + "\', sizingmethod = 'Scale'); \"> </span>"
IMG. outerhtml = strnewhtml
I = I-1
}
}
}
Function alphabackgrounds (){
VaR rslt = navigator. appversion. Match (/MSIE (D +. d + )/,'');
VaR itsallgood = (rslt! = NULL & number (rslt [1]) >=5.5 );
For (I = 0; I <document. All. length; I ++ ){
VaR BG = Document. All [I]. currentstyle. backgroundimage;
If (BG ){
If (BG. Match (/. PNG/I )! = NULL ){
VaR mypng = BG. substring (5, BG. Length-2 );
// Alert (mypng );
Document. All [I]. style. Filter = "progid: DXImageTransform. Microsoft. alphaimageloader (src = '" + mypng + "', sizingmethod = 'crop ')";
Document. All [I]. style. backgroundimage = "URL ('')";
// Alert (document. All [I]. style. Filter );
}
}
}
}
If (navigator. Platform = "Win32" & navigator. appname = "Microsoft Internet Explorer" & window. attachevent ){
Window. attachevent ("onLoad", correctpng );
Window. attachevent ("onLoad", alphabackgrounds );
}