Web Page Background Color Change with Javascript

 

Complete Code

<HTML>

<HEAD>

<SCRIPT LANGUAGE=”JavaScript”>

<!– Beginning of JavaScript –

function changecolor(code) {

document.bgColor=code

}

// – End of JavaScript – –>

</SCRIPT>

 

</HEAD>

<BODY>

<form>

<input type=”button” name=”Button1″ value=”RED” onclick=”changecolor(‘red’)>

<input type=”button” name=”Button2″ value=”GREEN” onclick=”changecolor(‘green’)>

<input type=”button” name=”Button3″ value=”BLUE” onclick=”changecolor(‘blue’)>

<input type=”button” name=”Button4″ value=”WHITE” onclick=”changecolor(‘white’)>

</form>

</BODY>

</HTML>

  • Share/Save/Bookmark

Javascript Message Box Example


Chapter 1, The Message Box

This is a very simple script. It opens up an alert message box which
displays whatever is typed in the form box below.

Type something in the box. Then click “Show Me”


HOW IT’S CODED

Here’s the entire page, minus my comments. Take a few minutes to learn as much
as you can from this, then I’ll break it down into smaller pieces.

<HTML>

<HEAD>

<SCRIPT LANGUAGE=”JavaScript”>

<!– Beginning of JavaScript –

function MsgBox (textstring) {

alert (textstring) }

// – End of JavaScript – –>

</SCRIPT>

</HEAD>

 

<BODY>

<FORM>

<INPUT NAME=”text1″ TYPE=Text>

<INPUT NAME=”submit” TYPE=Button VALUE=”Show Me” onClick=”MsgBox(form.text1.value)“>

</FORM>

</BODY>

</HTML>

  • Share/Save/Bookmark

Javascript Objects, Methods, Events

Objects and Properties

Your web page document is an object. Any table, form, button, image, or link on your page is also an object. Each object has certain properties (information about the object). For example, the background color of your document is written document.bgcolor. You would change the color of your page to red by writing the line: document.bgcolor=”red”
The contents (or value) of a textbox named “password” in a form named “entryform” is document.entryform.password.value.

Methods

Most objects have a certain collection of things that they can do. Different objects can do different things, just as a door can open and close, while a light can turn on and off. A new document is opened with the method document.open() You can write “Hello World” into a document by typing document.write(“Hello World”) . open() and write() are both methods of the object: document.

Events

Events are how we trigger our functions to run. The easiest example is a button, whose definition includes the words onClick=”run_my_function()”. The onClick event, as its name implies, will run the function when the user clicks on the button. Other events include OnMouseOver, OnMouseOut, OnFocus, OnBlur, OnLoad, and OnUnload.

  • Share/Save/Bookmark

Some Common FAQ about Javascipt

 

Are Javascript and Java the same?

No, they are two completely different computer languages. Only their names are similar. Actually Javascript is not Java and Java is not Javascript. You can say Java and Javascript is two different Animal.

What do we need to run Javascript?

Javascript support is built right into web browsers. Provided that the visitors to your site are using web browsers that support Javascript (most do) and have Javascript enabled (it is by default) then your Javascript will run.

Do I need to learn Javascript to be able to use it?

No. There are plenty of Javascripts that have already been written that people have made available for you to plug straight into your web page. All you need to know to be able to use such scripts is how to paste the supplied code into the required places in your web page.

What do I need to write Javascript?

Javascript is an interpreted language and so no special program is required to be able to create usable code. Any plain text editor such as Notepad is quite satisfactory for being able to write Javascript. That said, an editor which colourizes the code to make it easier to see what is what makes it easier to find your mistakes but then my Javascript Formatter can reformat your script to make errors even easier to spot.

Can I use HTML instead of Javascript?

No. HTML and Javascript are two completely different things. HTML is a markup language designed for defining static web page content. Javascript is a programming language designed for performing dynamic tasks.

Can I use PHP or some other server side language instead of Javascript?

Perhaps, it depends on where the code needs to run. If it can run before the page loads you can use a server side language. If it has to run after the page has loaded then you must use Javascript as this is the only scripting language supported by all web browsers that support client side scripting.

Does the Javascript go in the same file as the HTML?

It can but your scripts will be more easily reused on multiple pages of your site if you place them in separate files (using a .js extension helps identify them as Javascript). You then just link the Javascript to your HTML by inserting a <script> tag. The same Javascript can then be added to several pages just by adding the appropriate tag into each of the pages to set up the link.

 

  • Share/Save/Bookmark

Benefits of JavaScript

 

Javascript has Many benifits.  JavaScript’s main benefit is that it can be understood by the common human. It is much easier and more robust than Java. It allows for fast creation of web page events. Many JavaScript commands are what are known as Event Handlers: They can be embedded right into existing HTML commands. JavaScript is a little more forgiving than Java. It allows more freedom in the creation of objects. Java is very rigid and requires all items to be denoted and spelled out. JavaScript allows you to call on an item that already exists, like the status bar or the browser itself, and play with just that part. JavaScript is geared to web pages. Java is geared toward where it is needed most at the time.

Both will create great web page events. Both can offer interaction between the user and your Web page. But they are not created equally by any means.

So to answer the question of which to use where… use whichever fits your needs. That sounds like a cop-out answer, but remember that the applets and JavaScript are most often offered on the Net as fully functioning items. You simply grab them from the Net and use them on your page (provided you are given permission). There are many, many sites out there that do nothing more than hand out applets or JavaScript.

Gamelan.com is a good one for applets. Take a look at javascripts.com for over 2300 free JavaScript scripts. The HTML Goodies Applet and JavaScript Tutorials will teach you how to implement these items on your pages. They will not teach you to write the languages, but rather instruct you on placing functioning applets and JavaScript scripts on your Web pages. It is a good introduction to the formats. Once you know how to get these pups on your pages, you’ll understand more about their structures and can then more easily attempt to learn the language and create functioning JavaScripts or applets yourself.

 

  • Share/Save/Bookmark

What is JavaScript and how is it different from Java Technology?

The JavaScript programming language, developed by Netscape, Inc., is not part of the Java platform.

JavaScript, does not create applets or standalone applications. In its most common form today, JavaScript resides inside HTML documents, and can provide levels of interactivity to web pages that are not achievable with simple HTML.

Listed are key differences between the Java and JavaScript.

  • Java is an OOP programming language while Java Script is an OOP scripting language.
  • Java creates applications that run in a virtual machine or browser while JavaScript code is run on a browser only.
  • Java code needs to be compiled while JavaScript code are all in text.
  • They require different plug-ins.

Java vs. JavaScript: Similarities and Differences

They are both similar and quite different depending on how you look at them. First their lineage:

Java is an Object Oriented Programming (OOP) language created by James Gosling of Sun Microsystems. JavaScript is a scripting language that was created by the fine people at Netscape and was originally known as LiveScript. JavaScript is a (very) distant cousin of Java in that it is also an OOP language. Many of their programming structures are similar. However, JavaScript contains a much smaller and simpler set of commands than does Java. It is easier for the average weekend warrior to understand.

You may be wondering what OOP means by now. Object Oriented Programming is a relatively new concept, whereas the sum of the parts of a program make up the whole. Think of it this way: you are building a model car. You build the engine first. It can stand alone. It is an engine and everyone can see it’s an engine. Next you build the body. It can also stand alone. Finally, you build the interior including the seats, steering wheel, and whatnot. Each, by itself is a object. But it is not a fully functioning car until all the pieces are put together. The sum of the objects (parts) make up the whole.

Continuing with the model car example, when you built the engine, you didn’t use any of the parts that would later build the seats (a 350 four-barrel engine with a seat belt sticking out if the piston would look pretty silly). The point is that all the parts that made up the engine were of a certain class of parts. They all went together. Ditto with the body and then the interior.

The point is that in these languages, you build objects out of classes of commands to create the whole. Understand the terminology? Good. Moving along…

Java and JavaScript are Still Two Different Trees

Now let’s talk about how Java and JavaScript differ. The main difference is that Java can stand on its own while JavaScript must (primarily) be placed inside an HTML document to function. Java is a much larger and more complicated language that creates “standalone” applications. A Java “applet” (so-called because it is a little application) is a fully contained program. JavaScript is text that is fed into a browser that can interpret it and then it is enacted by the browser–although today’s web apps are starting to blur the line between traditional desktop applications and those which are created using the traditional web technologies: JavaScript, HTML and CSS.

Another major difference is how the language is presented to the end user (that’s you when you’re surfing). Java must be compiled into what is known as a “machine language” before it can be run on the Web. Basically what happens is after the programmer writes the Java program and checks it for errors, he or she hands the text over to another computer program that changes the text code into a smaller language. That smaller language is formatted so that it is seen by the computer as a set program with definite beginning and ending points. Nothing can be added to it and nothing can be subtracted without destroying the program.

JavaScript is text-based. You write it to an HTML document and it is run through a browser. You can alter it after it runs and run it again and again. Once the Java is compiled, it is set. Sure, you can go back to the original text and alter it, but then you need to compile again.

Java applets run independent of the HTML document that is calling for them (and Java is also what runs many appliances and mobile devices, and does not require a web browser). Sure, they appear on the page, but the HTML document did little more than call for the application and place it. If the programmer allows it, oftentimes parameters can be set by the HTML document. This includes the background color of the applet of the type of text it displays, etc. The delivery of the applet is done through a download. The HTML document calls for the application, it downloads to the user’s cache, and waits to run. JavaScript is wholly reliant on the browser to understand it and make it come to life.

  • Share/Save/Bookmark

What is Javascript?

Javascript is a programming language that is used to make web pages interactive. It runs on your visitor’s computer and so does not require constant downloads from your web site.

A Brief History of JavaScript

Proposed in 1962, the Internet was created in 1969, known then as the ARPANET, by the Advanced Research Projects Agency (ARPA), linking their four main computers in their four research headquarters in SouthWest USA. It had been four years since 1965, when they had first managed to connect two computers over the telephone system. By 1972, many computers in universities across the USA had been connected, and the email, newsgroup and telnet protocols were being developed. Many further internet protocols were developed in the 1970s and 1980s, such as FTP and Gopher, and the underlying TCP/IP protocol replaced the original NCP protocol in the early 1980s. And so the ARPANET became the Internet, a network of university and military computers connected to each other via many other computers, communicating using the TCP/IP protocol. The idea was that, even if the Cold War became real, and portions of the Internet were damaged by nuclear war, the remaining links could take over so the internet could still function.
The World Wide Web (which basically means using the HTTP protocol to retrieve hyperlinked documents) was proposed in March 1989 by Tim Berners-Lee, a British computer specialist, at the European Laboratory for Particle Physics (CERN) for Swiss scientists, so that they could easily publish and share their research with the 12 nations of the high-energy physics community. He created the world’s first browser, named ‘WorldWideWeb’, in 1990, and released it in 1991. In 1992, browsers became a worldwide tool for transmission of text based information, using the HTTP protocol. In 1993 the NCSA mosaic browser was created and offered the oportunity to use inline images, and colours and hyperlinks as well as plain text. It was also the first browser to run in a graphical interface environment. The first version of Netscape was released in 1994, written by a break-away group from the original Mosaic team.

The Javascript language is one of the most useful to come along in the history of the world wide web. It allows websites to be built that are much more interactive than the ones that came before them. Javascript was actually created to make better web browsers but it soon became obvious that it was also useful forwebsite developers. The result is the world wide web that we know today, with all of its interactivity.

Javascript was created during the mid nineties as a way to make web browsers more interactive. Up until that time most websites were very dull as they usually contained little besides text and had almost no interactivity. In order to address this problem when Netscape were developing their updated version of the Navigator browser they created Javascript in order to allow them to build a browser that would be more functional. With this they were very successful and Javascript soon became widely used for a number of other applications as well.

The main use of Javascript quickly went from building a better web browser to building a better website. It is used mainly to build dynamic web pages. A dynamic web page is simply one that shows new content every time somebody visits. In the early days of the web this wasn’t possible because of the limitations of HTML. It was really the development of PHP that made dynamic sites possible. However even this proved to be of limited value. What was really needed was a coding language that would allow for the development of sites that weren’t just dynamic but actually interactive.

This is something that Javascript made possible. On our own web siteYozo.be, we use Javascript intensely to make the page talk to the visitors as naturally as possible. It takes some skill, but it’s actually surprisingly simple.

Unlike most other programing languages that are used to create web pages it soon became apparent that there were a number of other potential uses for Javascript. Not only is it used to create web pages it is widely used in the development of PDF documents. This allows documents to be interactive as well. Javascript is also widely used in the development of desk top applications. The main reason for the popularity of Javascript is that it is a fairly easy language to learn and to code with.

One of the areas that has caused some controversy with Javascript is the name. It of course has a similar name to the popular programming language Java. In fact there is no relationship between them at all. They were developed completely independently of each other. However Sun Microsystems who did develop Java were involved in the announcement of the name, adding to the confusion. Most people have viewed this as a marketing ploy, a way to attract attention Netscape’s new browser. Although exactly what was in it for Sun Microsystems was never quite clear. Clearly some sort of arrangement was made but just what that is we are unlikely to ever know.

JavaScript name terminology

These names are subject to interpretation by the browser developers. For example, browsers may support what they call JavaScript1.5, but not even support DHTML. This makes the JavaScript version unreliable, do not rely on it.

ECMAscript : The core syntax for JavaScript, defining control stuctures, intrinsic objects and variable types, operators, functions, scope, etc.

DOM level 0 : Says how to refer to forms, inputs, images, links and anchors as children of the document object.

Layers DOM : Says how to refer to positioned elements (layers) and modify their style as children of the document object with nested references.

Proprietary DOM : Says how to refer to elements and modify their style using the all collection of the document or parent object and the style child object of the element.

W3C DOM : Says how to refer to elements and modify their style using various getElementBy… methods of the document or parent object and the style child object of the element. Also says how to represent all document elements as a tree structure. Also allows elements to be created, modified or deleted even after the document has loaded.

Mocha : An early name for JavaScript, not recognised by most browsers.

LiveWire : An early name for JavaScript, not recognised by most browsers, used as the name of Netscape’s server side JavaScript.

LiveScript : An early name for JavaScript, recognised by most browsers.

JavaScript : A collective name for all versions of JavaScript.

JavaScript1.0 : The first version of JavaScript to be released – Early ECMAscript + DOM level 0 without images.

JavaScript1.1 : Early ECMAscript + DOM level 0.

JavaScript1.2 : ECMAscript + DOM level 0 + layers or proprietary DOM.

JavaScript1.3 : More advanced ECMAscript + DOM level 0 + layers or proprietary DOM.

JavaScript1.4 : Server side JavaScript.

JavaScript1.5 : Even more advanced ECMAscript + DOM level 0 + W3C DOM.

JavaScript2.0 : JavaScript 1.5 with several extensions added by Mozilla – may become a future standard.

JScript : Microsoft’s JavaScript variations with extended core features.

Active scripting : Microsoft’s user friendly way of saying ‘JScript’.

JellyScript : WebTV’s interpretation of JavaScript.

InScript : iCab 3-‘s interpretation of JavaScript.

ECMAscript Mobile Profile : Parts of ECMAScript, basic JavaScript APIs, and DOM, all mixed together in a single specification. Incompatible in far too many ways with existing pages on the Web, current browsers, the ECMAScript pecification, the DOM specifications, the JavaScript documentation, and other well established practices. ECMAScript Mobile Profile should be ignored. It is harmful to the Web because of its incompatibilities.

 

  • Share/Save/Bookmark

How To Improve Your Adsense Income Fast And Easy

3 effective Rules to Increase your Google Adsense Income

Quite often website owners often forget these very simple tips, when it comes to using adsense in websites. Here are some the very simple golden tips, which may help you to maximize your adsense income.

  1. Dont waste your ad impressions and place your ads only in pages where your visitors are likely to click your ads.
  2. Blend your adsense ads along with the colors on your website.
  3. Dont put too many ads on a single page and avoid making your site look like ad selling site. You can pick the size of the ad which suits your page accordingly.

I have seen many people getting success with wide leader board (728×90) and large rectangle (336×280) sizes. Sometimes instead of just showing text ads, the images look much much better. So next time when you create a ad, just make sure that you allow both image and text ads.

 

You can go here and know more about google adsense ad format and sizes

Google AdSense

  • Share/Save/Bookmark

AdSense Make Money Online

How I Make This AdSense Income?

Do you want to monetize your content websites? One of the greatest and easiest ways to make money from your current websites is through Google Adsense Program. By adding Adsense code on your content webpages, you can easily earn back your hosting fees. If your websites have good traffic, you can make even hundreds to thousands of dollars a day!
Even if you have added Adsense code on your site already, you can still increase your profit by making some simple changes! Here are 8 proven methods to have a bigger check from Google:

1. Create a custom design to blend the ads. For example, if your website has a grey background, try to use grey as the color of the ad border and background I mean just mach ad color combination and your website color combination same. This will make the ads look like it is a part of your website, results in more clicks from your valued visitors.

2. Use Text Ads instead of Image Ads as users can have more choices. More choices mean bigger chances your visitors will click the ads they like.

3. Placing images above ads helps in attracting user attention.

4. There is a special kind of Adsense ads called AdLinks. Blend AdLinks with other navigation links or place horizontal adlinks at the top of your webpage.

5. Remember you for all time put the ads on the highly visible part of your website. For short articles, CTR (Click Through Rate) is best when the code are placed just above the content. For long articles, CTR increases if the code are placed somewhere in middle of the content – visitors read the long content and then they are looking for more resources. On the whole, test the CTR for placing ads in different locations in your website. You will be amazed how the difference between the locations can affect your earnings.

6. Try to mechanize the insertion of the Adsense code into the webpages using SSI (server side included).
Ask your web administrator if your web server supports SSI or not. Then how do you do it? Just save the code in a text file, e.g. save it as “adsense-code.txt”, and upload it to the root directory of the web server. Then use SSI, call the code on your web pages. This tip can save you lots of time especially if you are using generate pages automatically on your website using page generator.

7. If you want to add Google search box, open the search box results in a new browser window, so you won’t lose your visitors. Besides, the search box is better on the top right corner. So you know where to put it.

8. You can block low paying advertisers with Filters. Why would you like to loose a visitor for 0.01 cents, right?
These tips have been used by many websites to boost Adsense income. Try them on your website and see how well these tips can improve your income.

  • Share/Save/Bookmark

What is Google Adsense?

Google Adsense is a contextual program that gives webmasters the chance to earn some money from their websites. Webmasters can place Google Adsense ads on their web pages. The ads that are shown on the site are from the Google Adwords network, where Advertisers buy space on websites and pay per click through to their own websites. Every time an Adsense ad is clicked by a visitor to your site you get paid a share of the revenue that Google makes from charging the Advertiser to place Adsense ads on other websites. Below is a very simple guide on how to get started with Google Adsense”

Sign up to Adsense Click Here and it is now time to make an ad code and place it on your website to earn money.

Google Adsense ads will be relevant to the content that is on your site.

Google will start to deliver targeted ads to your site as soon as you place the code onto your site. Google Adsense will try and find relevant ads to place on your site and will match this with the sort of content you have on your page. This will help you in earning more money with Adsense as visitors are more likely to click on ads that are similar to the topic of your pages content.

Creating Your Own Adsense Code:

You need to login into your Adsense account and then once inside choose Adsense set-up. You then need to choose the ad-format. Many Adsense Publishers have had great success using the 336×280 Large Rectangular Square ad. Then once you have picked the Ad Format, you need to change the colours and make the ads fit the style of your website. Once you have done these steps you can add a channel that will track all the ads on your site and tell you which ads are performing better.
Your code should look like the one below:

<script type=”text/javascript”><!–
google_ad_client = “
Publisher ID Here“;
google_ad_width =
Width of the ad;
google_ad_height =
Height of the ad;
google_ad_format = “
chosen ad format“;
google_ad_type = “
Text, Image or Text and Image“;
google_ad_channel = “
The Name you have called the ad, to track stats“;
google_color_border = “
chosen border color“;
google_color_bg = “
chosen background color“;
google_color_link = “
chosen link color“;
google_color_url = “
chosen url color“;
google_color_text = “
chosen text color“;
//–>
</script>
<script type=”text/javascript”
src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”>
</script>


You need to copy the code into your website.

Once you have chosen your ad formats and are sure they will fit in well with your template you need to add the code to your files on your server. Once you have done this the Adsense ads will appear on your site in the places you intended them to be placed.

  • Share/Save/Bookmark