Javascript custom functions determine whether the site access type is PC or mobile

  • 2020-03-30 01:20:46
  • OfStack

Because many mobile terminals do not support Flash, so many colorful Flash effects do not come. If you can determine the type of Web page to access (PC or mobile). Can suit the medicine to the case, find the solution!

The type of access to the mobile terminal we will use. GIF instead of Flash(.swf suffix) animation, the PC side will not change. This is perfect!

As shown below, the function flashChecker() is used to detect the type of access.
 
<script language="javascript" type="text/javascript"> 
 
function flashChecker() { 
var hasFlash = 0; 
var flashVersion = 0; 
var isIE = 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> 

Expansion of:
 
<script language="javascript" type="text/javascript"> 
 
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> 

Related articles: