Home > Article > Web Front-end > js method to implement delayed loading of Flash_javascript skills
The example in this article describes how to implement delayed loading of Flash in js. Share it with everyone for your reference, the details are as follows:
When the page contains a flash player that automatically plays videos, the flash streaming media player will continue to download the video (even if you click play pause/stop, it will continue to download), which will affect the page Loading of other elements.
The simplest optimization method is to prevent Flash from playing at the beginning: of course, you can modify the fla source file so that the video playback is paused at the beginning until the user clicks the play button. But the problem is that if you embed a flash animation without source files, this approach will not work.
Thoughts:
You can first place a small picture where the flash is placed, click on the picture and then replace the picture element with the corresponding object tag.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>swf占位符</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js"></script> <script type="text/javascript"> $().ready(function () { $("#rbtvs_play_pos").click(function () { $("#swfPos").html("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0\" width=\"226\" height=\"338\" id=\"rbtvs_player\" align=\"middle\" style=\"z-index: -999\"><param name=\"allowScriptAccess\" value=\"Always\" /><param name=\"allowFullScreen\" value=\"false\" /><param name=\"movie\" value=\"http://img.rbtvs.com/swf/rbtvs_player.swf\" /><param name=\"quality\" value=\"high\" /><param name=\"bgcolor\" value=\"#efefef\" /><param name=\"wmode\" value=\"opaque\" /><embed src=\"http://img.rbtvs.com/swf/rbtvs_player.swf\" quality=\"high\" bgcolor=\"#efefef\" width=\"226\" height=\"338\" name=\"rbtvs_player\" align=\"middle\" allowscriptaccess=\"Always\" allowfullscreen=\"false\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.adobe.com/go/getflashplayer\" /></object>"); }) }) </script> </head> <body> <div id="swfPos"> <img id="rbtvs_play_pos" src="http://img.rbtvs.com/bihu001/images/rbtvs_play.gif" style="cursor:pointer" alt="点击播放视频" /> </div> </body> </html>
I hope this article will be helpful to everyone in JavaScript programming.