问题
I want to load some jQuery code before the DOM is ready. I want to make a flash file transparant as the DOM loads. I was going to use something like this but Flash is initilized before the DOM loads.
jQuery(document).ready(function(){
jQuery('object:not(:has(wmode))').each(function(){
jQuery(this).attr('wmode', 'transparent');
jQuery(this).prepend('<param name="wmode" value="transparent">');
jQuery(this).children('embed').attr('wmode', 'transparent');
});
});
Any ideas on how to do this?
EDIT
Hey guys, thanks for the help, Basically, The flash content is coming from our Advertisement Manager, which stupidly enough, doesn't allow direct editing of the HTML, as to add the required wmode attributed into the specific tags...
So Javascript is my only option...
回答1:
ready()
is the earliest point at which you can safely access arbitrary DOM elements.
You could put a script
block directly after you declare the object
tag: That should work, you will have access to the object
element.
However, I don't think even that will help you: As far as I know, Flash won't accept a JavaScript-side changing of the wmode
parameter anyway.
You would have to put wmode.transparent
into the HTML, or create the Flash movies dynamically when the DOM is loaded.
回答2:
Using javascript before the dom is loaded will yield to unpredictable results. Modify your html code as you wish, but do not use javascript.
回答3:
The safest way is to construct the object or embed element on dom ready event:
<div id="flash"></div>
$(document).ready(function(){
var htm= '<object ...><param name="some" value="val" ... /></object>';
$('#flash').html(htm);
});
来源:https://stackoverflow.com/questions/4124765/how-to-load-jquery-before-dom-is-ready