Javascript checks whether the flash plug-in is installed

Source: Internet
Author: User

I. Use scripts to detect
This method is used to get rid of the limitations of the previous method. For example, the behavior named "Check Plug-in" in DW
This method is still unavailable on some machines that cannot execute scripts, such as IE on IE4.5 or earlier versions on MAC and IE on WIN31.
Some users disable SCRPIT execution.

The simplest way

The code is as follows: Copy code

<Script language = "JavaScript">
<! --
Var swf = new ActiveXObject ('shockwaveflash. Shockwaveflash ');
(Swf )? Document. writeln ('you have installed the plug‑in '): document. writeln ('You have not installed plug‑in ');
// -->
</SCRIPT>

If you want to detect the flash version

The code is as follows: Copy code

<SCRIPT type = text/vbscript> <〉〈! --
// IE
On error resume next
Set f = CreateObject ("ShockwaveFlash. ShockwaveFlash")
If IsObject (f) then
I _flash = true
V_flash = hex (f. FlashVersion ())
End if
// --> </SCRIPT> 〉

<SCRIPT type = text/javascript> <〉〈! --
If (I _flash ){
Document. writeln ("you have installed the Flash plug-in")
If (v_flash ){
Document. writeln ("-version" + v_flash );
    }
} Else {
Document. writeln ("You have not installed the Flash plug-in")
    }
// --> //--〉
</SCRIPT> 〉

To enable normal playback of your Flash files on each user's browser, we must accurately know whether the user has installed the Flash Player plug-in and the version number of the plug-in. This detection can be done through Javascript.

The code is as follows: Copy code

<Script language = "JavaScript1.1">
<! --
// U can change this number to check specific version of flash
Var MM_contentVersion = 6;

Var plugin = (navigator. mimeTypes & navigator. mimeTypes ["application/x-shockwave-flash"])?
Navigator. mimeTypes ["application/x-shockwave-flash"]. enabledPlugin: 0;

If (plugin ){
Var words = navigator. plugins ["Shockwave Flash"]. description. split ("");
For (var I = 0; I <words. length; ++ I ){
If (isNaN (parseInt (words [I])
Continue;
Var MM_PluginVersion = words [I];
    }
Var MM_FlashCanPlay = MM_PluginVersion> = MM_contentVersion;
}
Else if (navigator. userAgent & navigator. userAgent. indexOf ("MSIE")> = 0 &&
(Navigator. appVersion. indexOf ("Win ")! =-1 )){
// FS hide this from IE4.5 Mac by splitting the tag
Document. write ('<SCR' + 'ipt LANGUAGE = VBScript> N ');
Document. write ('On error resume next n ');
Document. write ('Mm _ FlashCanPlay = (IsObject (CreateObject ("ShockwaveFlash. ShockwaveFlash." & MM_contentVersion) N ');
Document. write ('</SCR' + 'ipt> N ');
}

If (MM_FlashCanPlay ){
Alert ("Flash Detection OK. U can play .");
}
Else {
Alert ("Flash Detection Failed. Need Download specific version .");
}
// -->

</SCRIPT>

II. Use FLASH for detection
If you do not even execute SCRPIT, you can only use this method. This is also the method used by MM itself.
Make a moderation HTML with a SWF in it, containing only one GetURL ("Your real page ")
At the same time in the HTML <HEAD> inside the <META HTTP-EQUIV = "Refresh" CONTENT = "10; URL =" no FLASH installed Page ">
If SWF does not take you to the real page within 10 seconds, the detected HTML will take you to the page not installed.

Code

 

The code is as follows: Copy code
<! -- Start VBSCRIPT plugin detection -->
<Script language = VBScript>
Private I, x, MM_FlashControlVersion
On Error Resume Next
X = null
MM_FlashControlVersion = 0
Var Flashmode
FlashMode = False
For I = 5 To 1 Step-1
Set x = CreateObject ("ShockwaveFlash. ShockwaveFlash." & I)
       
MM_FlashControlInstalled = IsObject (x)
       
If MM_FlashControlInstalled Then
MM_FlashControlVersion = CStr (I)
Exit
End If
Next
FlashMode = (MM_FlashControlVersion> = 5)
If FlashMode = True Then
Document. write "HTML with FLASH"
Else
Document. write "HTML without FLASH"
End If
</SCRIPT> <! -- End vbscript plugin detection -->

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.