Html 如果 Adobe Flash 不可用,请提供替代图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/449808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Providing alternative images if Adobe Flash isn't available
提问by Gerhard Dinhof
Are there any ways providing an alternate GIF/PNG image, in case the user has no Adobe Flash installed and/or deactivated. I've found recommendations, like the following from W3C, which determine via JavaScript the existence of Adobe Flash on the client: W3C Providing alternative images
如果用户没有安装和/或停用 Adobe Flash,是否有任何方法提供备用 GIF/PNG 图像。我找到了一些建议,例如来自 W3C 的以下建议,这些建议通过 JavaScript 确定客户端上是否存在 Adobe Flash:W3C 提供替代图像
Honestly, I would prefer a non JStechnique. I'm thinking of some XHTML tag, equivalent to <noscript>
. (like <noobject>
if the object (in our case Flash) can't be displayed/loaded).
老实说,我更喜欢非 JS技术。我在想一些 XHTML 标签,相当于<noscript>
. (比如<noobject>
如果对象(在我们的例子中是 Flash)无法显示/加载)。
The reason for needing this separation is the following: The bank I'm working for will preferably display their banners in Flash format. In case it isn't possible a simple image should be shown. In the past it was solved very likely in the way mentioned before. We're currently working on a design refresh and that's where I stumbled upon this piece of code which makes me wonder if it's really the most elegant and compatible way of doing so.
需要这种分离的原因如下: 我工作的银行最好以 Flash 格式显示他们的横幅。如果不可能显示简单的图像。过去很可能是按照前面提到的方式解决的。我们目前正在进行设计更新,这就是我偶然发现这段代码的地方,这让我想知道它是否真的是最优雅和最兼容的方式。
Another ideathat strikes me: Is it actually possible to load Flash-objects in a JavaScript disabled environment?
另一个让我印象深刻的想法是:真的可以在禁用 JavaScript 的环境中加载 Flash 对象吗?
采纳答案by Kristian J.
Actually having flash installed but javascript turned off is a valid scenario. This should work across most browsers:
实际上安装了 Flash 但关闭了 javascript 是一个有效的场景。这应该适用于大多数浏览器:
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="800" height="600" id="flashContent">
<param name="movie" value="flash.swf" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="flash.swf" width="800" height="600">
<!--<![endif]-->
<img src="(...)" alt="Put your alternate content here" />
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
回答by Raithlin
I use the following code for graceful degradation. It works well.
我使用以下代码进行优雅降级。它运作良好。
<!--[if !IE]> -->
<object type="application/x-shockwave-flash" data="flash.swf" width="500" height="100">
<!-- <![endif]-->
<!--[if IE]>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
width="500" height="100">
<param name="movie" value="flash.swf" />
<!--><!--dgx-->
<param name="loop" value="false">
<param name="menu" value="false">
<param name="quality" value="high">
<img src="flash_replacement.png" width="500" height="100" alt="No Flash">
</object>
<!-- <![endif]-->
回答by balexandre
I don't know why you want to avoid javascript, it is the best solution when dealing with Flash.
我不知道您为什么要避免使用 javascript,它是处理 Flash 时的最佳解决方案。
using the SWFObjects Library(the best known so far for the matter) you can do this:
使用SWFObjects 库(迄今为止最著名的),您可以执行以下操作:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> My Home Page </title>
<meta name="viewport" content="width=780">
<script type="text/javascript" src="swfobject.js"></script>
</head>
<body>
<div id="splashintro">
<a href="more.html"><img src="splash_noflash.png" /></a>
</div>
<script type="text/javascript">
var so = new SWFObject("csplash.swf", "my_intro", "300", "240", "8", "#338899");
so.write("splashintro");
</script>
</body>
</html>
what the script does is replace the splashintrodiv with the flash file, if the browser does not support Flash, then does nothing and the splash_noflash.pngwill be shown.
脚本的作用是将splashintrodiv 替换为 flash 文件,如果浏览器不支持 Flash,则不执行任何操作并显示splash_noflash.png。
P.S.With this technique you are ready for the iPhone, instead of showing the blue cube, it will show the image :)
PS使用此技术,您已准备好使用 iPhone,而不是显示蓝色立方体,而是显示图像:)
回答by Andres Vargas
I find using inline styling to do the trick.
我发现使用内联样式来解决这个问题。
For example:
例如:
<div style="background-image: url('...');">
<object>
/* Embedded Flash */
</object>
</div>
回答by Sinju Moncy
We can provide an alternate GIF/PNG image, in case the user has no Adobe Flash installed and/or deactivated.
我们可以提供备用 GIF/PNG 图像,以防用户未安装和/或停用 Adobe Flash。
<object id="flashcontent classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="550px" height="400px">
<param name="movie" value="mymovie.swf" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="mymovie.swf" width="550px" height="400px">
<!--<![endif]-->
<p>
Fallback or 'alternate' content goes here.
This content will only be visible if the SWF fails to load.
</p>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
And also add this...
还要加上这个...
<script type="text/javascript">
swfobject.registerObject("flashcontent", "9", "/path/to/expressinstall.swf");
</script>
回答by GreaseJunkie
I have written an easy way to do this in CSS - no extra JavaScript at all.
我在 CSS 中编写了一个简单的方法来做到这一点 - 根本不需要额外的 JavaScript。
Name your ID/Class where your Flash movie resides and use a background image. Wrap your Flash movie within that div.
命名您的 Flash 影片所在的 ID/类并使用背景图像。将您的 Flash 影片包裹在该 div 中。
For example:
例如:
<div ID="MyFlashMovie"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="800" height="600" id="flashContent">
<param name="movie" value="flashMovie.swf" />... etc., etc.</object>
</div> etc.
Then in your CSS:
然后在你的 CSS 中:
#MyFlashMovie {
background: url("alternateGraphic.png");
background-repeat: no-repeat;
height: XXpx;
width: XXpx;
}
When the Flash isn't available, say on the iphone/pad, the graphic will display. The only drawback with this, that I have found, is that if your Flash movie uses a transparent background, you will see the alt graphic through the transitions. Just make a solid color within the Flash movie as your lowest layer (make sure it's the same bg color as the website) and it will look fine.
当 Flash 不可用时,例如在 iphone/pad 上,图形将显示。我发现这样做的唯一缺点是,如果您的 Flash 电影使用透明背景,您将通过过渡看到 alt 图形。只需在 Flash 电影中将纯色作为最低层(确保它与网站的背景颜色相同),它看起来会很好。
~GreaseJunkie
~油脂迷