如何在 DOM 准备好之前加载 jQuery
我想在 DOM 准备好之前加载一些 jQuery 代码。我想让 Flash 文件在 DOM 加载时透明。我打算使用类似的东西,但 Flash 在 DOM 加载之前就已初始化。
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');
});
});
关于如何做到这一点有什么想法吗?
编辑
嘿伙计们,感谢您的帮助,基本上,Flash 内容来自我们的广告管理器,它很愚蠢,不允许直接编辑 HTML,以便将所需的 wmode 添加到特定标签中......
所以Javascript是我唯一的选择......
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ready()
是您可以安全访问任意 DOM 元素的最早点。您可以在声明
object
标记后直接放置一个script
块:这应该可行,您将可以访问object
元素。然而,我认为这对您也没有帮助:据我所知,Flash 无论如何都不会接受 JavaScript 端对
wmode
参数的更改。您必须将
wmode.transparent
放入 HTML 中,或者在加载 DOM 时动态创建 Flash 影片。ready()
is the earliest point at which you can safely access arbitrary DOM elements.You could put a
script
block directly after you declare theobject
tag: That should work, you will have access to theobject
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.在 dom 加载之前使用 javascript 将产生不可预测的结果。
根据需要修改 html 代码,但不要使用 javascript。
Using javascript before the dom is loaded will yield to unpredictable results.
Modify your html code as you wish, but do not use javascript.
最安全的方法是在 dom 就绪事件上构造对象或嵌入元素:
The safest way is to construct the object or embed element on dom ready event: