Chapter 13 Answers
To enclose JavaScript code, you use
<script>
and</script>
tags.By default, JavaScript code will output to the part of the document in which it resides. If itâs in the head it will output to the head; if the body, then the body.
You can include JavaScript code from other sources in your documents by either copying and pasting them or, more commonly, including them as part of a
<script src='filename.js'>
tag.The equivalent of the
echo
andprint
commands used in PHP is the JavaScriptdocument.write
function (or method).To create a comment in JavaScript, preface it with
//
for a single-line comment or surround it with/*
and*/
for a multiline comment.The JavaScript string concatenation operator is the
+
symbol.Within a JavaScript function, you can define a variable that has local scope by preceding it with the
var
keyword upon first assignment.To display the URL assigned to the link with an ID of
thislink
in all main browsers, you can use the two following commands:document.write(document.getElementById('thislink').href) document.write(thislink.href)
The commands to change to the previous page in the browserâs history array are:
history.back() history.go(-1)
To replace the current document with the main page at the oreilly.com website, you could use the following command:
document.location.href = 'http://oreilly.com'
Get Learning PHP, MySQL, JavaScript, and CSS, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.