JavaScript gets flash objects different from the Web _javascript tips

Source: Internet
Author: User
About JS to get flash objects, there are a lot of examples on the Internet, I also tried a lot of methods.
Although it can be used, but not what I want most,
Later looked at Baidu, although very standard, all kinds of circumstances have taken into account, but the amount of code is not not optimistic,
Back and forth nearly 20 lines of code, after compression also has 864 bytes.

So this article was born.
I want to test and share some of the more satisfying ways I've collected online.
Also by the way please help test the compatibility, there are incompatible in the following leave a message, it is best to write the browser version, so I also good test and repair the code.
Let's look at the code here.
Copy Code code as follows:

function Getflashmovieobject (moviename) {
if (Window.document[moviename]) {
return Window.document[moviename];
}
if (Navigator.appName.indexOf ("Microsoft Internet") = = 1) {
if (document.embeds && document.embeds[moviename])
return Document.embeds[moviename];
} else {//if (Navigator.appName.indexOf ("Microsoft Internet")!=-1)
return document.getElementById (Moviename);
}
}

This method is relatively conservative, if the document is taken to the value of the direct return, if not taken, the author often used embeds compatible substitutes to take,
Of course, IE is to special treatment, but here the author often getElementById, and other places with window more.
Of course getElementById is not wrong, he takes the ID of object, because embeds only name has no ID.
Copy Code code as follows:

var flash = document["Myflash"] | | window["Myflash"];

This method is simpler and clearer, and I don't have much to nag about.
Copy Code code as follows:

var flash = document["Myflash"];

This is I read a variety of versions, I wrote, because I have a variety of browsers on the computer + virtual machine under the ie6-10 are tested, I also feel puzzled.
Of course, if the official use, I will still choose scheme one, but sometimes special circumstances, do not need to be compatible with multiple browsers, you can consider this OH.

The following is a practical example, using three methods to obtain the Flash object, and Flash control test.
If a friend found that can not test pass, trouble left the browser version number and can not pass the scheme, the younger brother first thanked.

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.