开发者

Where put SWFObject in JQuery

开发者 https://www.devze.com 2022-12-18 13:55 出处:网络
I have 2 javascripts in my head section. Now I want to place the embedSWF function inside the first script. Only I am not sure where..

I have 2 javascripts in my head section. Now I want to place the embedSWF function inside the first script. Only I am not sure where..

        <!-- JQUERY Functions -->
    <script type="text/javascript"> 
        jQuery.noConflict();
        jQuery(document).ready(function() {
            // alert('DOM ready');
 开发者_Go百科       });
        window.onload = function() {
            // alert('page completely loaded');
        }
    </script>

    <!-- write SWF -->
    <script type="text/javascript">
        function outputStatus(e) {
            if (!e.success) { // alert('NO flash, alternative content'); 
            } 
            else { // alert('flash embedded successfully'); 
            }
        }
        var flashvars = {};
        var params = {}
        swfobject.embedSWF("test.swf", "album-wrap", "930", "530", "9.0.0", "js/expressInstall.swf", flashvars, params, null, outputStatus); 
    </script>


You'd better move all the script from head to the bottom of the page, above the </body>. This will make the page load better, since loading javascript will block concurrent loading of other page element, such as css and image, that more required than the js code.

To put swfobject code, it's more safe to put it inside jQuery DOM ready block.

function outputStatus(e) {
  if (!e.success) {
    // alert('NO flash, alternative content'); 
  } 
  else {
    // alert('flash embedded successfully'); 
  }
}

jQuery(function($) {
  // alert('DOM ready');
  var flashvars = {};
  var params = {}
  swfobject.embedSWF("test.swf", "album-wrap", "930", "530", "9.0.0", "js/expressInstall.swf", flashvars, params, null, outputStatus);
});

This will make sure that the swfobject run after all required DOM have been loaded. If you do it outside the block, then it can have probability to run while still waiting the required DOM element to be loaded into page, that will give unexpected result.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号