常有网友提问,如何让网页中嵌入的Flash标签也符合web标准。目前还没有一个完美的解决办法,这篇文章中,我们将Flash嵌入标签写入js文件中,通过变量传递参数的办法来回避不符合标准的标签。
请注意,这只是一个变通的方法,换汤不换药,并未能最终解决存在的问题,通过验证只是一种表象,这样的思路是不是可取,在实际操作中请大家自行斟酌。
首先建立一个JS文件flash.js,写入如下代码:
function swf(file,w,h) {
document.write('<object classid=http://www.shancun.net/skin/default/image/nopic.gifclsid:D27CDB6E-AE6D-11cf-96B8-444553540000http://www.shancun.net/skin/default/image/nopic.gif codebase=http://www.shancun.net/skin/default/image/nopic.gifhttp://download.macromedia.com/pub/
shockwave/cabs/flash/swflash.cab#version=7,0,19,0http://www.shancun.net/skin/default/image/nopic.gif width=http://www.shancun.net/skin/default/image/nopic.gif'+w+'http://www.shancun.net/skin/default/image/nopic.gif height=http://www.shancun.net/skin/default/image/nopic.gif'+h+'http://www.shancun.net/skin/default/image/nopic.gif> ');
document.write('<param name=http://www.shancun.net/skin/default/image/nopic.gifmoviehttp://www.shancun.net/skin/default/image/nopic.gif value=http://www.shancun.net/skin/default/image/nopic.gif' + file + 'http://www.shancun.net/skin/default/image/nopic.gif>');
document.write('<param name=http://www.shancun.net/skin/default/image/nopic.gifqualityhttp://www.shancun.net/skin/default/image/nopic.gif value=http://www.shancun.net/skin/default/image/nopic.gifhighhttp://www.shancun.net/skin/default/image/nopic.gif> ');
document.write('<param name=http://www.shancun.net/skin/default/image/nopic.gifwmodehttp://www.shancun.net/skin/default/image/nopic.gif value=http://www.shancun.net/skin/default/image/nopic.giftransparenthttp://www.shancun.net/skin/default/image/nopic.gif> ');
document.write('<param name=http://www.shancun.net/skin/default/image/nopic.gifmenuhttp://www.shancun.net/skin/default/image/nopic.gif value=http://www.shancun.net/skin/default/image/nopic.giffalsehttp://www.shancun.net/skin/default/image/nopic.gif> ');
document.write('<embed src=http://www.shancun.net/skin/default/image/nopic.gif' + file + 'http://www.shancun.net/skin/default/image/nopic.gif quality=http://www.shancun.net/skin/default/image/nopic.gifhighhttp://www.shancun.net/skin/default/image/nopic.gif pluginspage=http://www.shancun.net/skin/default/image/nopic.gifhttp://www.macromedia.com/go/getflashplayerhttp://www.shancun.net/skin/default/image/nopic.gif type=http://www.shancun.net/skin/default/image/nopic.gifapplication/x-shockwave-flashhttp://www.shancun.net/skin/default/image/nopic.gif width=http://www.shancun.net/skin/default/image/nopic.gif'+w+'http://www.shancun.net/skin/default/image/nopic.gif height=http://www.shancun.net/skin/default/image/nopic.gif'+h+'http://www.shancun.net/skin/default/image/nopic.gif></embed> ');
document.write('</object> ');
}
上面的js脚本定义了一个函数swf,并设置三个变量,它们分别是:flile文件链接,w宽度,h高度。在XHTML中向这个函数传递变量即可实现flash的嵌入。如下代码:
<div id=http://www.shancun.net/skin/default/image/nopic.gifflashhttp://www.shancun.net/skin/default/image/nopic.gif>
<script type=http://www.shancun.net/skin/default/image/nopic.giftext/javascripthttp://www.shancun.net/skin/default/image/nopic.gif language=http://www.shancun.net/skin/default/image/nopic.gifjavascripthttp://www.shancun.net/skin/default/image/nopic.gif>swf('designyesky.swf','500','220');</script>
</div>
建立id为flash的div作为一容器,在其内部嵌入js脚本,变量依次为:文件路径、宽度、高度。
看下面的全部代码:
<!DOCTYPE html PUBLIC http://www.shancun.net/skin/default/image/nopic.gif-//W3C//DTD XHTML 1.0 Transitional//ENhttp://www.shancun.net/skin/default/image/nopic.gif http://www.shancun.net/skin/default/image/nopic.gifhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtdhttp://www.shancun.net/skin/default/image/nopic.gif>
<html xmlns=http://www.shancun.net/skin/default/image/nopic.gifhttp://www.w3.org/1999/xhtmlhttp://www.shancun.net/skin/default/image/nopic.gif>
<head>
<meta http-equiv=http://www.shancun.net/skin/default/image/nopic.gifContent-Typehttp://www.shancun.net/skin/default/image/nopic.gif content=http://www.shancun.net/skin/default/image/nopic.giftext/html; charset=gb2312http://www.shancun.net/skin/default/image/nopic.gif />
<title>符合web标准的嵌入Flash的方法</title>
<script type=http://www.shancun.net/skin/default/image/nopic.giftext/javascripthttp://www.shancun.net/skin/default/image/nopic.gif language=http://www.shancun.net/skin/default/image/nopic.gifjavascripthttp://www.shancun.net/skin/default/image/nopic.gif src=http://www.shancun.net/skin/default/image/nopic.gifflash.jshttp://www.shancun.net/skin/default/image/nopic.gif></script>
<style type=http://www.shancun.net/skin/default/image/nopic.giftext/csshttp://www.shancun.net/skin/default/image/nopic.gif>
#flash { width:500px; margin:50px auto; border:5px solid #03c;}
</style>
</head>
<body>
<div id=http://www.shancun.net/skin/default/image/nopic.gifflashhttp://www.shancun.net/skin/default/image/nopic.gif>
<script type=http://www.shancun.net/skin/default/image/nopic.giftext/javascripthttp://www.shancun.net/skin/default/image/nopic.gif language=http://www.shancun.net/skin/default/image/nopic.gifjavascripthttp://www.shancun.net/skin/default/image/nopic.gif>swf(designyesky.swf','500','220');</script>
</div>
</body>
</html>