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



Question:

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?


Solution:1

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.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »