首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pngfix不适用于IE6中的flash对象

Pngfix不适用于IE6中的flash对象
EN

Stack Overflow用户
提问于 2011-07-27 20:44:32
回答 1查看 170关注 0票数 0

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

在我需要支持的IE6中,flash对象之后的每个图像都不包含在png fix用于遍历图像的document.images中,因此png fix不会被应用。你知道怎样才能让剩下的图片出现在这个列表中吗?(我正在寻找替换brightside组的徽标,它确实显示了新的图像)

非常感谢您的帮助!

pngfix脚本:

代码语言:javascript
复制
// 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
      }
   }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-27 22:07:22

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

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

代码语言:javascript
复制
<!--[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。

代码语言:javascript
复制
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"); 
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6844489

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档