Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Monday, 13 August 2012

JavaScript Is Easy

Filled under:


One reason JavaScript is so popular is that it’s relatively easy to add JavaScript to a web page. All you need to do, at a minimum, is include an HTML script element in the page, specify "text/javascript" for the type attribute, and add whatever JavaScript you want:
<script type="text/javascript">
...some JavaScript
</script>
Installation is not required, nor do you have to torturously work through any odd library path configurations. JavaScript works, straight out of the box and in most web browsers, including the big five: Firefox, Internet Explorer, Chrome, Opera, and Safari. All you need to do is add a scripting block, and you’re in business.
Traditionally, you add JavaScript blocks to the head element in the document (delimited by opening and closing head tags), but you also can include them in the body element— or even in both sections. However, adding script to the body is not usually considered a good technique, as it makes it more difficult to find the script when you’re modifying it at a later time. The exception to this rule is when performance is an issue, which we'll since in the upcoming articles on JavaScript.
Hello World!
Also traditionally, the first example when learning a new programming language is
known as “Hello, World”—a simple application that prints out “Hello, World!” to the
user interface, whatever it may be. In the case of JavaScript, the user interface is the
web page.
The example below shows a web page with a JavaScript block that, using only one
line of JavaScript, pops open a small window commonly called an alert box with the
words “Hello, World!”
The smallest JavaScript application: “Hello, World!”
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Hello, World!</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
alert("Hello, World!");
</script>
</head>
<body>
</body>
</html>
  • Copy and paste the above code into your text editor save as helloworld.html. The saved file will now look like an internet document just click on it, it will opened in your web browser with the alert "Hello World"

Posted By Unknown8:36:00 am

Sunday, 12 August 2012

A Tale about JavaScript

Filled under:


A long time ago, JavaScript was called LiveScript. In a classic “if you can’t dazzle them with brilliance, baffle them with marketing” move, Netscape changed the name to take advantage
of the burgeoning interest in Java (another programming language that Netscape partner Sun Microsystems was developing at the time). By all accounts, the strategy worked. Unfortunately, many newbies still mistake JavaScript for Java, and vice versa.
Here’s the scoop: Java is similar to JavaScript in that they’re both object-based languages developed
for the Web. Without going into the nitty gritty details of syntax, interpreters, variable typing, and just-in-time compilers, all you have to remember about the difference in usage between
JavaScript and Java is this: On the gigantic client/server application that is the Web, JavaScript lets you access Web clients (otherwise known as browsers), and Java lets you access Web servers. (Note: In some cases, you can also use Java for Web client development.)
This difference might seem esoteric, but it can help you determine which language to use to create the Web site of your dreams. If what you want to accomplish can be achieved inside the confines of a Web client (in other words, by interacting with HTML, browser plug-ins, and Java applets), JavaScript is your best bet. But if you want to do something fancier — say, interact with a server-side database — you need to look into Java or some other server-side alternative.

Posted By Unknown1:34:00 am
BthemesandTricks is loading comments...