简体   繁体   English

为什么defer属性对不能在Firefox中不提供外部js文件的脚本标签起作用?

[英]Why doesn't the defer attribute work on script tags that don't source an external js file in Firefox?

Why doesn't the defer attribute work on script tags that don't source an external js file in Firefox? 为什么defer属性对不能在Firefox中不提供外部js文件的脚本标签起作用?

lets say an ancient cms only allows me to add javascript to templated pages via in-page [script]...my code...[/script] tags and strips any html tags entered into the content area field, thus preventing me from embedding scripts just above [/body]. 可以说,一个古老的cms仅允许我通过页内[script] ...我的代码... [/ script]标记将javascript添加到模板化页面,并剥离输入到内容区域字段中的所有html标记,从而阻止了我在[/ body]上方嵌入脚本。

But since all my code does is manipulate the DOM I need it to not run until after the page has loaded and I don't feel like jumping through the hoop of attaching a function to the window's onload which then calls another function which then runs my code. 但是由于我所有的代码都是在操纵DOM,所以我需要它在页面加载后才运行,而且我不希望跳过将函数附加到窗口onload的过程,然后再调用另一个函数再运行我的DOM码。

So, what was the reasoning behind not allowing the defer attribute on script tags that don't use the src attribute? 那么,在不使用src属性的脚本标签上不允许defer属性的背后原因是什么?

You can't rely on the defer attribute because it's not widely supported. 您不能依赖defer属性,因为它不受广泛支持。 Use something like this , if you want to execute scripts when the document is loaded. 如果要在加载文档时执行脚本,请使用类似这样的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM