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