Where to embed JavaScript scripts

Source: Internet
Author: User

JavaScript scripts can be placed anywhere in the HTML document where they are needed. In general, you can place JavaScript script code between

One, placed between

JavaScript script code placed between

1<Html>2<Head>3<Title> Placed in<Head> and</Head> Between tag Pairs</Title>4<!--Write JavaScript code directly-5<ScriptType= "Text/javascript">6//JavaScript code7</Script>8<!--Introducing External Scripts-9<Scripttype= "Text/javascript"  Src= "1.js" ></< Span style= "color: #800000;" >script>10 </< Span style= "color: #800000;" >head>11 <body>12 </< Span style= "color: #800000;" >body>13 </< Span style= "color: #800000;" >html>           

B. Place between <body> and </body> mark pairs

JavaScript scripts can also be placed between <body> and </body> tag pairs, and can be written as many separate script snippets as needed and combined with HTML code.

1<Html>2<Head>3<Title> Placed in<body> and</Body> Between tag Pairs</Title>4</Head>5<Body>
6 <!--Write JavaScript code directly-
7<ScriptType= "Text/javascript">
8     //javascript code
9 script>
<!-- introduce external script --
11 <script type= "Text/javascript" Src= "1.js" ></< Span style= "color: #800000;" >script> </body> </html>

Note: There can be multiple blocks of code within the

Description: Browsers typically render HTML from top to bottom, and when JavaScript code is encountered, the browser will block (no longer parsing any subsequent code, including HTML and JavaScript). Some browsers do not parse the HTML code behind the JavaScript during blocking, and must wait until the JavaScript code has finished executing before parsing continues. This behavior often occurs when you place JavaScript between

Therefore, we strongly recommend placing JavaScript code at the end of <body>...</body> without special requirements. Such as:

<Body><!--HTML code -<Scripttype= "Text/javascript"></scirpt><Script Type="Text/javascript"src="1.js"></scirpt></body>


Original link: http://www.itxueyuan.org/view/6297.html

Where to embed JavaScript scripts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.