views:

23

answers:

1

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

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].

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.

So, what was the reasoning behind not allowing the defer attribute on script tags that don't use the src attribute?

A: 

You can't rely on the defer attribute because it's not widely supported. Use something like this, if you want to execute scripts when the document is loaded.

galambalazs