HTML 사전

script

설명

The script element is used to embed or reference an executable script within an HTML or XHTML document.

<script> 요소는 HTML 또는 XHTML 문서 안에 실행이 가능한 스크립트를 끼워넣거나 참조할 때 사용한다.

Usage Context

Permitted content Dynamic script such as text/javascript.
Tag omission None, must have both a start tag and an end tag.
Permitted parent elements Any element that accepts metadata elements, or any element that accepts phrasing content.
Normative document HTML5, section 4.3.1 (HTML4.01, section 18.2.1)

속성

이 엘리먼트는 전역속성을 지원한다.

 async - HTML5

Set this Boolean attribute to indicate that the browser should, if possible, execute the script asynchronously. It has no effect on inline scripts (i.e., scripts that don't have the src attribute). In older browsers that don't support the async attribute, parser-inserted scripts block the parser; script-inserted scripts execute asynchronously in IE and WebKit, but synchronously in Opera and pre-4.0 Firefox. In Firefox 4.0, the async DOM property defaults to true for script-created scripts, so the default behavior matches the behavior of IE and WebKit. To request script-inserted external scripts be executed in the insertion order in browsers where the document.createElement("script").async evaluates to true (such as Firefox 4.0), set .async=false on the scripts you want to maintain order. Never call document.write() from an async script. In Gecko 1.9.2, calling document.write() has an unpredictable effect. In Gecko 2.0, calling document.write() from an async script has no effect (other than printing a warning to the error console).

브라우저에서 스크립트를 비동기적으로 (asynchronously) 실행시키게 하려면 <script async>라고 써 주자. 인라인 스크립트에는 아무 영향을 주지 않는다. 인라인 스크립트라 함은 src 속성을 갖지 않는 스크립트를 의미한다. async속성을 지원하지 않는 이전 브라우저에서는 파서가 삽입(?? parser-inserted)한 스크립트가 파서를 차단한다(??). 스크립트가 삽입한(scripts-inserted) 스크립트(??)는 IE와 WebKit에서는 비동기적으로 실행(??)되고, Opera와 파이어폭스 4.0 이전 버전에서는 동기적으로 실행된다.  파이어폭스 4.0에서는, 스크립트가 생성한 스크립트에 대해서는 async DOM 속성의 디폴트값이 true이다. 즉, 디폴트 행동특성(behavior)이 IE와 WebKit에서와 동일하다. Firefox 4.0과 같이 document.createElement("script").async가 true로 평가되는 브라우저상에서 스크립트-삽입된 외부 스크립트가 삽입 순서에 의해 실행되도록 요청하기 위해서, 순서를 유지하고 싶은 스크립트들에겐 .async=false로 세팅하라. 절대로 async 스크립트로부터 document.write() 매서드를 콜하지 마라. Gecko 1.9.2에선, document.write()를 콜하는 것은 예상불가능한 효과가 있다. Gecko 2.0에선, async 스크립트로부터 document.write()를 콜하는 것은 효과가 없다. (에러콘솔로 warning을 출력하는 것 이외에는)

영어검토자의 번역버전 : - 기술검토하시는 분이 살펴보시고, 내용적으로 말이 되는지 살펴봐주시면 좋겠네요~
async속성은 불리언속성이며, 브라우저가 스크립트를 비동기적 방식으로 실행할지 여부를 지정해준다. src속성이 없는 스크립트를 인라인 스크립트라고 부르는데, async속성은 인라인 스크립트에는 아무 영향을 미치지 않는다. async속성을 지원하지 않는 구버전의 브라우저에서는 파서가 삽입한 스크립트가 파서를 블럭한다. 그리고 스크립트가 삽입한 스크립트는 IE와 WebKit에서 비동기적으로 실행되고, Opera와 파이어폭스 4.0이전 버전에서는 동기적으로 실행된다. 파이어폭스 4.0버버전에서 async DOM 속성은 스크립트가 만들어낸 스크립트에 대해서는 true를 기본값으로 갖는다. 그래서 기본작동방식은 IE와 WebKit에서의 작동방식과 같다. Firefox 4.0과 같이 document.createElement("script").async가 true로 평가되는 브라우저상에서 스크립트가 삽입한 외부 스크립트를 삽입순서대로 실행되게 하려면, 순서를 유지하고 싶은 스크립트들에 .async=false로 세팅하라. async 스크립트에서 document.write()를 호출하지 말라. Gecko 1.9.2버전에서 document.write()를 호출하면 예상할 수 없는 결과가 나올 것이다. Gecko 2.0버전에서async 스크립트에서 document.write()를 호출하면 경고창이나 에러콘솔이 뜨는 것 외에는 아무 영향이 없다. 

src

This attribute specifies the URI of an external script; this can be used as an alternative to embedding a script directly within a document. script elements with an src attribute specified should not have a script embedded within its tags.

이 속성은 외부 스크립트의 URI를 지정한다. 이것은 문서에 직접 스크립트를 집어넣는 대신으로 사용할 수 한다. src 속성이 명시된 스크립트 요소들은 내용안에 태그가 들어간 스크립트를 갖지 말아야 한다.

type

This attribute identifies the scripting language of code embedded within a script element or referenced via the element’s src attribute. This is specified as a MIME type; examples of supported MIME types include text/javascript, text/ecmascript, application/javascript, and application/ecmascript. If this attribute is absent, the script is treated as JavaScript.

이 속성은 요소의 src속성으로 참조된 코드나 script요소안에 들어간 코드의 스크립팅 언어를 식별한다. MIME타입으로 정의되어져 있다. 지원되는 MIME 타입의 예는 다음을 포함한다--text/javascript, text/ecmascript, application/javascript, 그리고 application/ecmascript. 만약 이 속성이 없다면, 스크립트는 자동적으로 JavaScript로 간주된다.

language - Deprecated 폐지예정

Like the type attribute, this attribute identifies the scripting language in use. Unlike the type attribute, however, this attribute’s possible values were never standardized. The type attribute should be used instead.

type속성과 같이, 이 속성은 사용되는 스크립팅 언어의 종류를 식별한다. type속성과 다르게 이 속성의 가능한 값들이 하나도 표준화되지 못했다. type속성이 대신 쓰여야 한다.

defer

This Boolean attribute is set to indicate to a browser that the script is meant to be executed after the document has been parsed. Since this feature hasn't yet been implemented by all other major browsers, authors should not assume that the script’s execution will actually be deferred. Never call document.write() from a defer script (since Gecko 1.9.2, this will blow away the document). The defer attribute shouldn't be used on scripts that don't have the src attribute. Since Gecko 1.9.2, the defer attribute is ignored on scripts that don't have the src attribute. However, in Gecko 1.9.1 even inline scripts are deferred if the defer attribute is set.

 이 불린 속성은 문서가 다 파싱된 후에 스크립트가 실행되도록 브라우저에게 표기하기 위함입니다. 이 기능은 아직 모든 주요 브라우저들에 의해 채택되지 않았기 때문에, 저작자들은 실제로 스크립트의 실행이 ‘defer'(연기)될 것이라고 장담해서는 않됩니다. 절대로 document.write()를 'defer'(연기)된 스크립트로부터 콜하지 마세요(Gecko 1.9.2부터는, 이 기능이 문서를 날려 버릴 것입니다.). defer속성은 src속성이 없는 스크립트한테는 쓰여지지 말아야 합니다. Gecko 1.9.2후로는, defer 속성은 src속성이 없는 스크립트한테는 무시됩니다. 하지만, Gecko 1.9.1에서는 인라인 스크립트들도 만약 defer속성이 세팅되어있다면 연기됩니다.

예제

<!-- HTML4 and (x)HTML -->
<script type="text/javascript" src="javascript.js">

<!-- HTML5 -->
<script src="javascript.js"></script>

DOM Interface

 This element implements the HTMLScriptElement interface.

호환성

Desktop
기능 구글크롬 파이어폭스Gecko) 인터넷 익스플로러 Opera Safari
기본적인 지원 1.0 1.0 (1.7 or earlier) 지원 지원 지원
async attribute 지원 3.6 (1.9.2) 10   지원
defer attribute 지원 3.5 (1.9.1) 4   지원
Mobile
기능 안드로이드 파이어폭스 모바일(Gecko) 인터넷 익스플로러 모바일 오페라 모바일 사파리 모바일
기본적인 지원 지원 1.0 (1.0) 지원 지원 지원
async attribute 지원 1.0 (1.0)     지원
defer attribute 지원 1.0 (1.0)     지원

참고

댓글

댓글 본문
버전 관리
김나솔
현재 버전
선택 버전
graphittie 자세히 보기