Pngfix在IE6中无法使用flash对象

时间:2011-07-27 12:44:32

标签: flash internet-explorer-6 pngfix

我有一个网站 - http://gap.quotamarketing.co.uk/ - 在这个网站上我有一个pngfix。我也有一个flash对象。

在我需要支持的IE6中,flash对象之后的每个图像都不包含在png修复用于循环遍历图像的document.images中,因此不会应用png修复。任何想法如何让其他图像出现在这个列表中? (我希望更换明亮的组徽标,它真的用新图像显示)

任何帮助都非常感谢!

pngfix脚本:

// JavaScript Document
/*

Correctly handle PNG transparency in Win IE 5.5 & 6.
http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.

Use in <HEAD> with DEFER keyword wrapped in conditional comments:
<!--[if lt IE 7]>
<script defer type="text/javascript" src="pngfix.js"></script>
<![endif]-->

*/

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters)) 
{
   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.cssText 
         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
      }
   }
}

1 个答案:

答案 0 :(得分:1)

我不熟悉pngfix,但你应该考虑使用SWFObject来嵌入你的Flash对象。然后,您可以延迟Flash对象插入页面,直到您的pngfix完成。因为你的pngfix脚本使用defer来推迟它的执行,直到页面被加载,你将不得不采取类似的措施来延迟SWFObject的初始化。

我这样做的方法是在条件注释块中设置一个我们可以在外面检查的变量。如果它不存在,那么您可以使用SWFObject继续并嵌入SWF,否则,您将从pngfix脚本的末尾调用嵌入。

<!--[if lt IE 7]>
<link href="includes/ie6print.css" rel="stylesheet" type="text/css" media="print" />
<link href="includes/ie6template.css" rel="stylesheet" type="text/css" media="screen" />

<script type="text/javascript">var horribleOldBrowser = true;</script>

<script defer type="text/javascript" src="includes/pngfix.js"></script>
<![endif]-->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<script type="text/javascript">
    if(typeof horribleOldBrowser === 'undefined') {
        //must not be using pngfix, let's embed with swfobject now
        swfobject.embedSWF("Flash/formFlash2.swf", "myTargetContainer", "300", "210", "9.0.0");
</script>

然后,在pngfix脚本的末尾,你再次放入相同的Javascript行,以便在一切完成时嵌入swfobject。

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters)) 
{
   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.cssText 
         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
      }
   }
   swfobject.embedSWF("Flash/formFlash2.swf", "myTargetContainer", "300", "210", "9.0.0"); 
}