DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> HTML基礎知識 >> HTML和Xhtml
XHTML 中的 Flash 呼叫技巧:改用 JS 動態輸出
編輯:HTML和Xhtml     

傳統直接寫 Flash 嵌入碼的做法存在幾個痛點:難以通過標準驗證、在 IE7 中會出現虛線邊框影響視覺,而且每嵌入一段就是一大塊程式碼,不利於同一頁面放多個 Flash。以下提供一個改用 JavaScript 動態輸出的解法。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml" lang="utf-8">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function flash (ur ,w ,h ){
document.write('<object classid="clsid:D27CDB6E-AE6D-11CF-96B8-444553540000" id="obj1" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" border="0" width="'+w+'" height="'+h+'">');
document.write('<param name="movie" value="'+ur+'">');
document.write('<param name="quality" value="High">');
document.write('<embed src="'+ur+'" pluginspage="https://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" name="obj1" width="'+w+'" height="'+h+'">');
document.write('</object>');
}
</script>
</head>
<body>
<script type="text/javascript">flash('https://client.joy.cn/flvplayer/451974_1.swf','100','80');</script>
<br />
<br />
<script type="text/javascript">flash('https://www.flash8.net/uploadflash/68/flash8net_67466.swf','500','375');</script>
</body>
</html>

相較於傳統寫法,這個做法的優點包括:

  1. 能通過標準驗證。
  2. 不會出現 IE 的虛線邊框。
  3. 可重複呼叫。若把 head 中的那段 JS 獨立成一個外部檔案再引用,能省下大量程式碼——以單純的呼叫行數計算也比直接嵌入 Flash 精簡,特別是當網站多處需要插入 Flash 時效益更明顯。
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved