Javascript custom function to determine whether the Website access type is PC or mobile terminal

Source: Internet
Author: User

Because many mobile terminals do not support Flash, many colorful Flash effects can be achieved. If you can determine the type of the Web page (PC or mobile terminal) You want to visit ). You can find a solution to this problem!

For mobile phones, we use the. gif replacement for flash (.swf suffix) animation, and the PC side will not change. This is perfect!

As shown below, the flashChecker () function is used to detect access types.
Copy codeThe Code is as follows:
<Script language = "javascript" type = "text/javascript">
/*
* Used to detect whether a PC or a mobile terminal is used
* Return value: flashChecker (). f = true PC terminal
* Vice versa: Mobile Terminal
*/
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>

Expansion:
Copy codeThe Code is as follows:
<Script language = "javascript" type = "text/javascript">
/*
* Output swf animation based on parameters
* Url: Click the jump address after the swf animation.
* SwfLink: *. swf clip address
*/
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 = '000000' 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 = '000000' height = '55' align = 'middle' allowscriptaccess = 'never 'Type = 'application/x-shockwave-flash'" +
"Pluginspage = '" + url + "'/>" +
"</Object> ";


Return html;
}
</Script>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.