-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathScript.cfm
More file actions
26 lines (26 loc) · 1.55 KB
/
Script.cfm
File metadata and controls
26 lines (26 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<cfinclude template="/Inc/html.cfm">
<cfinclude template="/Inc/body.cfm">
<h1>The <script> tag</h1>
You want to separate your JavaScript from the html, so use:
<pre>
<!DOCTYPE html><br><html><br><head><br><meta charset="utf-8">
<title></title>
</head><br><body><br><div id="msg">
</div>
<script src="http://www.google.com/jsapi"></script>
<script>
google.load("jquery", "1", {uncompressed:true});
</script>
<script src="YourJavaScriptGoesHere.js"></script>
</body>
</html>
</pre>
By putting it at the bottom of the page, you are able to work with the page after the elements have loaded.<br>
Early examples of JavaScript used the <code>document.write</code> command, but the preferred method to write to the screen is now to wait until the document loads and then add text.
<p>
Why separate your JavaScript from the html? I can think of several reasons. </p>
<p>1. Because it's faster. If it's in an external file, it can be cached by the browser.</p>
<p>2. More importantly, suppose you are working with a designer, and the designer needs to be editing the html. If the JavaScript is in a separate file, you can be editing it without worrying the other person on your team.</p>
<p>3. By making it unobtrustive, it's more portable. Just like an external css file can be linked from multiple pages, (every page on the site has the same look), a .js file can give every page the same behaviors.</p>
<cfinclude template="/Library/html/foot.cfm">
<cfinclude template="/Inc/End.cfm">