JavaScript code used to determine whether flash is loaded

Source: Internet
Author: User

First, define the progress bar display layer: CopyCode The Code is as follows: <div> <SPAN class = "Intro"> download progress: </span>
<Div class = "barborder">
<Div class = "bar" id = "loadpercent"> </div>
</Div>
</Div>

Define the ad layer:Copy codeThe Code is as follows: <Div id = "showad"> </div>
Define the flash display layer:
<Div id = "showswf" class = "show" style = "display: none;">
<Object ID = "flashgame" ...... content omitted ......>
</Object>
</Div>

JS Code:Copy codeThe Code is as follows: <script language = "JavaScript">
If (window. Navigator. useragent. indexof ("Firefox")> = 1) // determines whether the browser is Firefox. Firefox does not support the percentloaded () function
{
Document. getelementbyid ("loadpercent"). innerhtml = "Firefox! No attentions ";
Document. getelementbyid ("showswf"). style. Display = 'block ';
}
Else
{
Refreshprogress ();
}

Function show () // hide the ad layer and display the flash Layer
{
Document. getelementbyid ("showad"). style. Display = 'none ';
Document. getelementbyid ("showswf"). style. Display = 'block ';
}

Function refreshprogress () // refresh progress bar Function
{
VaR downprogresswidth = 502;
VaR bar = Document. getelementbyid ("loadpercent ");
VaR movie = Document. getelementbyid ("flashgame ");
VaR npercentloaded = math. Abs (movie. percentloaded ());
Bar. style. width = math. Ceil (downprogresswidth * npercentloaded/100) + "PX ";
Bar. innerhtml = npercentloaded + "% ";

If (npercentloaded = 100)
{
Bar. style. width = (downProgressWidth-2) + "PX"; bar. innerhtml = "game download is complete"; show ();
}
Else
{
SetTimeout ('refreshprogress () ', 0 );
}
}

In fact, the best code is to look at some flash game websites and how to control them.Source codeYou can learn more about the knowledge and skills.

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.