Responsive Web Content: JavaScript

It's 1995! and suddenly you can put a lot of stuff on a web page: buttons, images, textboxes, "applets", etc.

Next problem: Who is the traffic cop/zoo keeper/manager of all that stuff?

In 1995 Brendon Eich of Netscape created a new language called "LiveScript" to run in web browsers that would provide a link from HTML to Java applets embedded in the web page, and also manage the interaction among page controls (i.e., buttons) and page elements (i.e., text boxes).

It was renamed "JavaScript" to indicate its intended role as a link between web page controls and Java applets.


What's a Java applet?

An "applet" is a small application. An regular-sized application is a big-deal computer program like Microsoft Word.

A Java applet is written in the Java programming language. It is compiled to "byte code" and embedded in a web page with the <applet> tag. Your web browser finishes the compilation of the applet and throws it onto the screen.

Show me an example of an applet   This is a "wireframe" dinosaur. It will change view based on your mouse cursor movement.

alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason." Your browser is completely ignoring the <APPLET> tag!

Java applets were designed to bring complex functionality to the web page. Think engineering design, financial calculations, 3-D graphics, real-time downloads from web pages, etc.

For security, applets run in a "sandbox" configuration - they can't read files on a client machine, start a process on a client machine, etc. They can only communicate with their host machine and other web pages.

No applet? Just a grey rectangle and no dinosaur? If you're using IE 6 pull down Tools > Internet Options > Advanced and then scroll down and click the box to activate Java for <applet>. You'll have to restart IE 6. A bit of a bother, no? Any idea why the world of IT is arranged like this?



What is Java?

Java is a fully object-oriented programming language developed by Sun Microsystems. One feature of Java is that an application can be compiled to byte code once and then ported to many different platforms..."Write once, run everywhere." Java is the premier programming language for the Web. It is the paradigm for more recent programming languages such as Microsoft's C# (pronounced see sharp).

Who do you think was threatened by the rise of Java and Sun Microsystems?

Geo-political, business strategy, realpolitik, Darwinian economical question: How important is it to "control the browser"? If you control the browser, could you make it difficult for a competitor's product to run inside your browser? Hmmm? Does the word "dinosaur" mean anything to you? What about the word "extinct"?

JavaScript and DHTML

JavaScript's success was due to its low barrier to entry (no compiler was needed, scripts could be copied and pasted into an HTML page, and it was the key technology for producing Dynamic HTML.)

JavaScript's weaknesses: Scripts are totally dependent on browser environment (i.e., they run in the browser and so if your browser doesn't fully implement JavaScript, your scripts won't work) and code is always exposed (i.e., no way to maintain intellectual property). There is no IDE (Integrated Development Environment) or debugger, and JavaScripts can be damn tricky to debug! (A personal comment)

Technical Efficiency Reason for JavaScript's Success: We live in client-server world. There will always be more clients than servers. Server efficiency dictates that work should be pushed out to the client's machine. Hence, the more that can be done on a client, the more server resources you can free up and therefore do more work overall. In short, if JavaScript didn't exist, something equivalent would have to be invented.

Something to think about:

Look at the source code of this web page; it is an example of DHTML (did you see the little box flying around?) My code is available for all. Careful inspection will show you that I also import some JavaScript with src="../pageHeading.js". You can have that file too with a little digging around.

This is an admirable example of open-source, public-spirited community on the web. Yes or No?

What would happen if you configured your web browser not to run JavaScript? How public spirited would that be?

What if you pasted my flying box code into your page? Stealing? Sharing? Open-source? Who would care? How would I find out?

What if I encourage you to take it, but insist you say that it comes from Terry Brooks' web page? Is that a win-win situation? How does it accrue to my advantage?

Implementation of a JavaScript in HTML

<html>
	<head>
		<script language = "JavaScript">
			The script is listed here
		</script>
	</head>
	<body>
		The body of the HTML here
	</body>
</html>

 

An Example of JavaScript: Click a Button

        JavaScript!

<script language="JavaScript">
	function setRed() {
	 var e = document.getElementById("exampleHeading");
	 e.style.color="red";
	}
	function setBlue() {
	 var e = document.getElementById("exampleHeading");
	 e.style.color="blue";
	}
</script>

<input type="button" value="Red Text" onclick="setRed()">
<input type="button" value="Blue Text" onclick="setBlue()">
<strong id="exampleHeading">JavaScript!</strong>
	

 

An Example of JavaScript: Roll over an Image

Two famous IT personalities:

         

<script language="JavaScript">
	function doDuke(){
	var e = document.getElementById("personality");
	e.value = "Duke";
	}
	function doClip(){
	var e = document.getElementById("personality");
	e.value = "Mr. Paper Clip";
	}
</script>

<p>Two famous IT personalities:</p>
<img src="Duke.JPG" onmouseover="doDuke()">
<img src="paperClip.JPG" onmouseover="doClip()">
<input type=text id="personality" length=30>