Introduction to JavaScript
What is JavaScript?
Java and JavaScript
JavaScript Allows Interactivity
How Does It Work?
JavaScript Statements
<html>
<head><title>My Page</title></head>
<body>
<script language="JavaScript">
document.write('This is my first →
JavaScript Page');
</script>
</body>
</html>
Note the symbol for �line continuation
JavaScript Statements
<html>
<head><title>My Page</title></head>
<body>
<script language=“JavaScript">
document.write('<h1>This is my first →
JavaScript Page</h1>');
</script>
</body>
</html>
HTML written
inside JavaScript
Document.write is the JS “Method”
JavaScript Statements
<html>
<head><title>My Page</title></head>
<body>
<p>
<a href="myfile.html">My Page</a>
<br />
<a href="myfile.html"
onMouseover="window.alert('Hello');">
My Page</A>
</p>
</body>
</html>
JavaScript written
inside HTML
An Event
Example Statements
<script language="JavaScript">
window.prompt('Enter your name:','');
</script>
<form>
<input type="button" Value="Press" onClick="window.alert('Hello');">
</form>
Another event
Note quotes: " and '
JavaScript window.alert Method
Alert Box
Syntax
window.alert(‘sometext’);
alert(‘I am an alert box!’);
onerror Event
Execute a JavaScript if an error occurs when loading an image:
<img src="image.gif" onerror="myFunction()">
So – useful in XSS….
If you reference an image file that does not exist, it will run the error function/method
<img src=“NoFile.gif” onerror=alert(‘VulnerableToXSS’)>