萬盛學電腦網

 萬盛學電腦網 >> 圖文處理 >> Flash教程 >> 如何調用Flash才符合Web網頁標准

如何調用Flash才符合Web網頁標准

  常有網友提問,如何讓網頁中嵌入的Flash標簽也符合web標准。目前還沒有一個完美的解決辦法,這篇文章中,我們將Flash嵌入標簽寫入js文件中,通過變量傳遞參數的辦法來回避不符合標准的標簽。

  請注意,這只是一個變通的方法,換湯不換藥,並未能最終解決存在的問題,通過驗證只是一種表象,這樣的思路是不是可取,在實際操作中請大家自行斟酌。

 

  首先建立一個JS文件flash.js,寫入如下代碼:

  function swf(file,w,h) {

  document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/
 

shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+w+'" height="'+h+'"> ');

  document.write('<param name="movie" value="' + file + '">');

  document.write('<param name="quality" value="high"> ');

  document.write('<param name="wmode" value="transparent"> ');

  document.write('<param name="menu" value="false"> ');

  document.write('<embed src="' + file + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'"></embed> ');

  document.write('</object> ');

  }

  上面的js腳本定義了一個函數swf,並設置三個變量,它們分別是:flile文件鏈接,w寬度,h高度。在XHTML中向這個函數傳遞變量即可實現flash的嵌入。如下代碼:

  <div id="flash">

  <script type="text/javascript" language="javascript">swf('designyesky.swf','500','220');</script> 

  </div>

  建立id為flash的div作為一容器,在其內部嵌入js腳本,變量依次為:文件路徑、寬度、高度。

  看下面的全部代碼:

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  <html xmlns="http://www.w3.org/1999/xhtml">

  <head>

  <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

  <title>符合web標准的嵌入Flash的方法</title>

  <script type="text/javascript" language="javascript" src="flash.js"></script> 

  <style type="text/css">

  #flash { width:500px; margin:50px auto; border:5px solid #03c;}

  </style>

  </head> 

  <body>

  <div id="flash">

  <script type="text/javascript" language="javascript">swf(designyesky.swf','500','220');</script> 

  </div>

  </body>

  </html>

copyright © 萬盛學電腦網 all rights reserved