由於許多行動終端不支援 Flash,因此 許多絢麗多彩的 Flash效果出不來。如果,能夠判斷存取Web網頁的類型(PC還是行動終端)。就可以對症下藥,找出解決的辦法! 存取的類型為移動終端我們就用.gif取代Flash(.swf後綴)動畫,PC端就不做改變。這樣就比較完美了! 如下圖,函數 flashChecker() 就是用來偵測存取的型別。 複製程式碼 程式碼如下: <BR>/* <BR>*用來偵測是PC還是行動終端<BR>*回傳:flashChecker().f == true PC終端<BR>* 反之為行動終端<BR>*/ <BR>function flashChecker() { <BR>var hasFlash = 0; <BR>var flashVersion = 0; <BR>var isIE = /*@cc_on!@*/0; <BR>if (isIE) { <BR> var swf = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); <BR>if (swf) { <BR>hasFlash = 1; <BR>VSwf = swf.GetVariable("$version"); VSwf.split(" ")[1].split(",")[0]); <BR>} <BR>} <BR>else { <BR>if (navigator.plugins && navigator.plugins.length > 0) { <BR>var swf = navigator.plugins["Shockwave Flash"]; <BR>if (swf) { <BR>hasFlash = 1; <BR>var words = swf.description.split(" "); <BR>for (var i = 0; i < words.length; i) { <BR>if (isNaN(parseInt(words[i]))) { <BR>continue; <BR>} <BR>flashVersion = parseInt(words[i]); <BR>} <BR>} <BR>} <BR>} <BR>return { <BR>f: hasFlash, v: flashVersion <BR>}; <BR>} <BR>} <BR>}; > 擴充:複製程式碼複製程式碼 程式碼如下: <BR>/* <BR>* 依照參數輸出swf動畫<BR>* url :點選swf動畫後的跳躍位址<BR>* swfLink: *.swf 素材位址<BR>*/ <BR>function GetSwfHtml(url, swfLink) { <BR>html = "<a style='position: absolute; top: 0; left: 0; bottom 0; right: 0; display: block; " <BR>"width: 100%; height: expression(this.parentNode.scrollHeight); filter: alpha(opacity=0);" <BR>"opacity: 0; backgroundity : #FFF;' href='" url "' target='_blank'>" <BR>"" <BR>"<object width='590' height='55' align='middle'> " <BR>"<param name='allowScriptAccess' value='never' />" <BR>"<param name='quality' value='high' />" <BR>"<param name='wmode' value='transparent' />" <BR>"<param name='movie' value='" swfLink "' />" <BR>"<embed wmode='transparent' src='" swfLink "' quality=' high' " <br>"width='590' height='55' align='middle' allowscriptaccess='never' type='application/x-shockwave-flash' " <br>"pluginspage='" url "' />" <BR>""; <BR><BR><BR>return html; }