JavaScript Instance Tutorial (3) Probe Browser plugin

Source: Internet
Author: User
Tags arrays object contains
javascript| Tutorial | Browsers use JavaScript to detect plug-ins in Web browsers, but it is worth pointing out whether it works only in Netscape Navigator. The following code shows how to probe the Audio/midi type plug-in:


<script language= "JavaScript" ><!--

var can_play = false;

var mimetype = ' Audio/midi ';

if (navigator.mimetypes) {

if (Navigator.mimetypes[mimetype]!= null) {

if (Navigator.mimetypes[mimetype]

. Enabledplugin!= null) {

Can_play = true;

document.write (' <embed src= "Sound.mid"

Hidden=true loop=false autostart=false> ');

}

}

}






function PlaySound () {

if (document.embeds && can_play) {

if (navigator.appname = ' Netscape ')

Document.embeds[0].play ();

Else

Document.embeds[0].run ();

}

}






function Stopsound () {

if (document.embeds && can_play)

Document.embeds[0].stop ();

}

--></script>






So how do you call it on the Web? Here is the specific code:


<a href= "#" onmouseout=

"Stopsound ()" >

height= "border=" "0" ></A>



You may be familiar with some other programming languages, such as C + + or Java, and so on, they can also create objects, and now the latest VB version of VB.net also has a better object-oriented features-----create objects. Essentially, the idea of creating an object is simply to create a simple entity that contains many properties and methods. The following is an example of an object builder:



function person (name, age, colour) {

THIS.name = name;

This.age = age;

This.colour = colour;

}






Then we can call the person constructor like this:






var somebody = new Person ("Patrick", "Red");

Or get input values from the user:



var pname = prompt ("What is your name");

var pAge = prompt ("How old Are You");

var pcolour = prompt ("What is your favourite colour?");

var somebody = new Person (pname, PAge, Pcolour);






All the constructors in JavaScript, as in Java, can be invoked using the New keyword. When a person uses its properties {"Patrick",
When "Red" is created (or constructed), these values can be accessed, such as:



Somebody.name, or


somebody["Name"]


"Patrick."


Somebody.age, or


Somebody["Age"]


22


Somebody.colour, or


Somebody["colour"]


"Red"


Because we have added the attributes of person by name, they must be referenced by name, as you can see in the following code. If we use numbers, then we have to use numbers to refer to, such as using somebody[0, instead of Somebody.name. JavaScript arrays and objects, such as
Forms,images,frames,... ) allows both methods.


In addition, arrays and objects have an intrinsic attribute, that is, length. We can use it this way when coding: Objectname.length, which returns the number of elements or attributes that an object contains.


Turn from: Dynamic Network production guide www.knowsky.com

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.