由於許多行動終端不支援 Flash,因此 許多絢麗多彩的 Flash效果出不來。如果,能夠判斷存取Web網頁的類型(PC還是行動終端)。就可以對症下藥,找出解決的辦法!
存取的類型為行動終端我們就用.gif取代Flash(.swf後綴)動畫,PC端就不做改變。這樣就比較完美了!
如下圖,函數 flashChecker() 就是用來偵測存取的型別。
<script language="javascript" type="text/javascript"> /* *用来检测是 PC还是移动终端 *返回:flashChecker().f == true PC终端 * 反之为移动终端 */ function flashChecker() { var hasFlash = 0; var flashVersion = 0; var isIE = /*@cc_on!@*/0; if (isIE) { var swf = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); if (swf) { hasFlash = 1; VSwf = swf.GetVariable("$version"); flashVersion = parseInt(VSwf.split(" ")[1].split(",")[0]); } } else { if (navigator.plugins && navigator.plugins.length > 0) { var swf = navigator.plugins["Shockwave Flash"]; if (swf) { hasFlash = 1; var words = swf.description.split(" "); for (var i = 0; i < words.length; ++i) { if (isNaN(parseInt(words[i]))) { continue; } flashVersion = parseInt(words[i]); } } } } return { f: hasFlash, v: flashVersion }; } </script>
擴充:
<script language="javascript" type="text/javascript"> /* * 根据参数 输出swf动画 * url :单击 swf动画 后的跳转地址 * swfLink: *.swf 素材地址 */ function GetSwfHtml(url, swfLink) { html = "<a style='position: absolute; top: 0; left: 0; bottom: 0; right: 0; display: block; " + "width: 100%; height: expression(this.parentNode.scrollHeight); filter: alpha(opacity=0);" + "opacity: 0; background: #FFF;' href='" + url + "' target='_blank'>" + "</a>" + "<object width='590' height='55' align='middle'>" + "<param name='allowScriptAccess' value='never' />" + "<param name='quality' value='high' />" + "<param name='wmode' value='transparent' />" + "<param name='movie' value='" + swfLink+ "' />" + "<embed wmode='transparent' src='" + swfLink+ "' quality='high' " + "width='590' height='55' align='middle' allowscriptaccess='never' type='application/x-shockwave-flash' " + "pluginspage='" + url + "' />" + "</object>"; return html; } </script>
更多Javascript自訂函數判斷網站存取類型是PC還是行動終端相關文章請關注PHP中文網!