Home > Web Front-end > JS Tutorial > body text

Can You Embed Inline Script in an External JavaScript File Using the \'src\' Attribute?

Mary-Kate Olsen
Release: 2024-10-28 12:03:54
Original
450 people have browsed it

Can You Embed Inline Script in an External JavaScript File Using the

Can You Embed Inline Script in an External JavaScript File Using the SRC Attribute?

While JavaScript is typically included using an external script file, a common question arises: can an inline script be incorporated within that external file using the src attribute?

According to the HTML 4.01 specification:

"The script may be defined within the contents of the SCRIPT element or in an external file. If the src attribute is not set, user agents must interpret the contents of the element as the script. If the src has a URI value, user agents must ignore the element's contents and retrieve the script via the URI."

In other words, it's either an inline script or an external script loaded via the src attribute. The two methods cannot coexist in the same script tag.

Clarification:

The src attribute always takes precedence over the inline script code. If a script tag includes both a src attribute and an inline script, browsers will disregard the inline script and only load the external JavaScript file specified by the src attribute.

The above is the detailed content of Can You Embed Inline Script in an External JavaScript File Using the \'src\' Attribute?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!