|
HTML Home
HTML TutorialHTML Tutorial HomeAbout HTML Getting Started HTML Elements HTML Formatting HTML Attributes HTML Colors HTML Links HTML Images HTML Meta Tags HTML Comments HTML Forms HTML Tables HTML Image Maps HTML Frames HTML Entities HTML Layouts HTML Styles HTML Scripts HTML Website Templates Website Hosting Summary HTML Code GeneratorsHTML Code GeneratorHTML Table Generator Marquee Generator Music Code Generator HTML Text Generator Text Box Generator Free HTML CodesHTML Background CodeHTML Comment Box Codes HTML Font Codes HTML Picture Codes HTML Marquee Code HTML Music Codes More Codes... HTML ReferenceComplete HTML Tag ListHTML Special Characters Hex Color Codes HTML Help |
HTML ScriptsA script is a small, embedded program that can add interactivity to your website. For example, a script could generate a pop-up alert box message, or provide a dropdown menu. Because HTML doesn't actually have scripting capability, you need to use the The Adding a ScriptYou can specify whether to make a script run automatically (as soon as the page loads), or after the user has done something (like click on a link). In either case, a generally accepted convention is to place your scripts between the HTML Code:
This would open a JavaScript alert as soon as the page loads. Triggering a ScriptIn many cases, you won't want the script to run automatically. You might only want the script to run if the user does something (like hover over a link), or once the page has finished loading. These actions are called intrinsic events (events for short). There are 18 pre-defined intrinsic events that can trigger a script to run. You use event handlers to tell the browser which event should trigger which script. These are specified as an attribute within the HTML tag. Lets say you want a message to display in the status bar whenever the user hovers over a link. The act of hovering over the link is an event which is handled by the HTML Code:
Treat yourself to a <a href="http://www.great-workout.com/killer-ab-workout.cfm" onMouseover="window.status='Go on, you know you want to'; return true">Killer Ab Workout</a>
This results in:
Treat yourself to a Killer Ab Workout
Status bar messages aren't supported by all browsers. If you see no change to the status bar, it's likely that your browser doesn't support this piece of JavaScript. Before we move on, check out the list of intrinsic events as specified by HTML 4.01 Calling an External ScriptYou can also place your scripts into their own file, then call that file from your HTML document. This is useful if you want the same scripts available to multiple HTML documents - it saves you from having to "copy and paste" the scripts into each HTML document. This makes it much easier to maintain your website. HTML Code:
<script type="text/javascript" src="external_scripts.js"></script>
Hide Scripts from Older BrowsersAthough most (if not all) browsers these days support scripts, some older browsers don't. If a browser doesn't support JavaScript, instead of running your script, it would display the code to the user. To prevent this from happening, you can simply place HTML comments around the script. Older browsers will ignore the script, while newer browsers will run it. HTML Code:
Alternate Information for Older BrowsersYou can also provide alternative info for users whose browsers don't support scripts (and for users who have disabled scripts). You do this using the HTML Code:
Set a Default Scripting LanguageYou can specify a default scripting language for all your HTML Code:
Note that you can still override the default by specifying a language within the script tag. Enjoy this website?
Oh, and thank you for supporting Quackit! |
FREE Hosting!With every domain name you register with ZappyHost, you get FREE (ad supported) hosting.PLUS you get:
Featured Template:
(Build your websites in minutes!) Got a MySpace Page?Get "www.yourname.com" for your MySpace page. Learn how >>. |