Wednesday, June 5, 2019
HTML and Javascript Tutorial
hypertext mark-up language and Java account book Tutorialhypertext markup language Basic DocumentDocument name goes hereVisible text goes here charge ElementsLargest Heading . . . . . . . . . . . . Smallest HeadingText ElementsThis is a paragraph (line break) (horizontal rule)This text is pre initialisetedLogical StylesThis text is emphasizedThis text is strongThis is some computer statutePhysical StylesThis text is b experiencedThis text is italicLinks, Anchors, and Image ElementsThis is a LinkSend e-mailA named anchorUseful Tips contributionJump to the Useful Tips SectionUnordered list premier(prenominal) itemNext itemOrdered listFirst itemNext itemDefinition listFirst termDefinitionNext termDefinitionTablessomeheadersomeheadersometextsometextFramesFormsApplesBananasCherriesEntities is the alike as is the same as is the same as Other ElementsText quoted from some source. hide 1Address 2CityComm scarcely Used Character EntitiesNote Entity names are case sensitiveThe Meta El ementAs we explained in the previous chapter, the head sortion contains general information (meta-information) about a document.hypertext markup language excessively includes a meta piece that goes inside the head element. The purpose of the meta element is to provide meta-information about the document.Most a great deal the meta element is calld to provide information that is relevant to wind vane browsers or search engines like describing the content of your document.Keywords for Search Engines close to search engines on the WWW will use the name and content attributes of the meta tag to index your rogues.The intention of the name and content attributes is to describe the content of a page.However, since too many meshmasters have used meta tags for spamming, like repeating keywords to give pages a higher ranking, some search engines have stopped using them entirely. reproducible Resource LocatorsSomething called a Uniform Resource Locator (URL) is used to address a docume nt (or early(a) data) on the World Wide Web. A salutary Web address like this http//www.w3schools.com/html/lastpage.htm follows these syntax rulesscheme//host.domainport/ caterpillar track/ commitnameThe scheme is defining the type of Internet service. The some commons type is http.The domain is defining the Internet domain name like w3schools.com.The host is defining the domain host. If omitted, the default host for http is www.The port is defining the port number at the host. The port number is normally omitted. The default port number for http is 80.The path is defining a path (a sub directory) at the server. If the path is omitted, the resource (the document) must be located at the root directory of the Web site.The filename is defining the name of a document. The default filename aptitude be default.asp, or index.html or something else depending on the settings of the Web server.URL SchemesSome examples of the most common schemes sackister be found belowAccessing a Newsg roupThe following hypertext markup language codeHTML Newsgroup causes a link to a newsgroup like this HTML NewsgroupDown bucking with FTPThe following HTML codeDownload WinZipcreates a link to transfer a file like this Download WinZip.(The link doesnt work. Dont try it. It is just an example. W3Schools doesnt really have an ftp directory.)Link to your Mail systemThe following HTML codeemailprotectedcreates a link to your own mail system like thisInsert a Script into HTML PageA script in HTML is fructifyd with the tag. Note that you will have to use the type attribute to specify the scripting language.How to Handle Older BrowsersA browser that does non hump the tag at all, will display the tags content as text on the page. To prevent the browser from doing this, you should hide the script in comment tags. An old browser (that does not recognize the tag) will ignore the comment and it will not write the tags content on the page, while a new browser will understand that the scr ipt should be penalise, even if it is surrounded by comment tags.ExampleNew to HTML 4.0 is the ability to let HTML events trip up actions in the browser, like pass overing a JavaScript when a exploiter clicks on an HTML element. Below is a list of attributes that can be inserted into HTML tags to define event actions.Window EventsOnly valid in body and frameset elements.Only valid in form elements.Keyboard EventsNot valid in base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, and title elements. snarf EventsNot valid in base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, title elements.Your Windows PC as a Web ServerIf you want other people to view your pages, you must put under them.To publish your work, you must save your pages on a web server.Your own PC can act as a web server if you constitute IIS or PWS.IIS or PWS turns your computer into a web server.Microsoft IIS and PWS are free web server components.IIS - Intern et Information ServerIIS is for Windows system like Windows 2000, XP, and Vista. It is also available for Windows NT.IIS is easy to install and ideal for exploitation and testing web applications.IIS includes Active Server Pages (ASP), a server-side scripting standard that can be used to create dynamic and interactive web applications.PWS - Personal Web ServerPWS is for older Windows system like Windows 95, 98, and NT.PWS is easy to install and can be used for developing and testing web applications including ASP.We dont recommend running PWS for anything else than training. It is outdated and have security issues.Windows Web Server VersionsWindows Vista Professional comes with IIS 6.Windows Vista Home Edition does not support PWS or IIS.Windows XP Professional comes with IIS 5.Windows XP Home Edition does not support IIS or PWS.Windows 2000 Professional comes with IIS 4.Windows NT Professional comes with IIS 3 and also supports IIS 4.Windows NT Workstation supports PWS and IIS 3.W indows ME does not support PWS or IIS.Windows 98 comes with PWS.Windows 95 supports PWS.HTML SummaryThis tutorial has taught you how to use HTML to create your own web site.HTML is the universal markup language for the Web. HTML lets you format text, add graphics, create links, input forms, frames and tables, etc., and save it all in a text file that any browser can meditate and display.The key to HTML is the tags, which indicates what content is coming up.XHTMLXHTML reformulates HTML 4.01 in XML.CSSCSS is used to control the style and layout of multiple Web pages all at once.With CSS, all formatting can be removed from the HTML document and stored in a separate file.CSS gives you total control of the layout, without messing up the document content.JavaScript TutorialWhat is JavaScript?JavaScript was designed to add interactivity to HTML pagesJavaScript is a scripting languageA scripting language is a lightweight programming languageJavaScript is usually embedded directly into HTML pagesJavaScript is an interpreted language (means that scripts execute without antecedent compilation)Everyone can use JavaScript without purchasing a licenseWhat can a JavaScript Do?JavaScript gives HTML designers a programming tool - HTML authors are normally not programmers, but JavaScript is a scripting language with a very simple syntax Almost anyone can put small snippets of code into their HTML pagesJavaScript can put dynamic text into an HTML page - A JavaScript statement like this document.write( + name + ) can write a variable text into an HTML pageJavaScript can react to events - A JavaScript can be set to execute when something happens, like when a page has finished loading or when a exploiter clicks on an HTML elementJavaScript can read and write HTML elements - A JavaScript can read and change the content of an HTML elementJavaScript can be used to validate data - A JavaScript can be used to validate form data before it is submitted to a server. This saves the serv er from extra processingJavaScript can be used to detect the visitors browser - A JavaScript can be used to detect the visitors browser, and - depending on the browser - load another page specifically designed for that browserJavaScript can be used to create cookies - A JavaScript can be used to store and convalesce information on the visitors computerHow to Put a JavaScript Into an HTML PageWhere to Put the JavaScriptJavaScripts in a page will be executed flat while the page loads into the browser. This is not always what we want. Sometimes we want to execute a script when a page loads, other times when a user triggers an event.Scripts in the head section Scripts to be executed when they are called, or when an event is triggered, go in the head section. When you place a script in the head section, you will ensure that the script is loaded before anyone uses it.Scripts in the body section Scripts to be executed when the page loads go in the body section. When you place a script in the body section it generates the content of the page.Scripts in both the body and the head section You can place an unlimited number of scripts in your document, so you can have scripts in both the body and the head section.Using an External JavaScriptSometimes you might want to run the same JavaScript on several pages, without having to write the same script on every page.To simplify this, you can write a JavaScript in an external file. Save the external JavaScript file with a .js file extension.Note The external script cannot contain the tagTo use the external script, point to the .js file in the src attribute of the tagJavaScript is Case SensitiveUnlike HTML, JavaScript is case sensitive - therefore watch your capitalization closely when you write JavaScript statements, create or call variables, objects and functions.JavaScript StatementsA JavaScript statement is a command to the browser. The purpose of the command is to tell the browser what to do.This JavaScript statement t ells the browser to write Hello Dolly to the web pageIt is normal to add a semicolon at the end of each executable statement. Most people think this is a good programming practice, and most often you will see this in JavaScript examples on the web.The semicolon is optional (according to the JavaScript standard), and the browser is supposed to interpret the end of the line as the end of the statement. Because of this you will often see examples without the semicolon at the end.Note Using semicolons makes it possible to write multiple statements on one line.JavaScript CodeJavaScript code (or just JavaScript) is a sequence of JavaScript statements. to each one statement is executed by the browser in the sequence they are written.This example will write a header and two paragraphs to a web pageJavaScript BlocksJavaScript statements can be grouped to countenanceher in blocks.Blocks start with a left curly square bracket , and ends with a right curly bracket .The purpose of a block is to make the sequence of statements execute together.This example will write a header and two paragraphs to a web pageJavaScript comments can be used to make the code more readable.JavaScript CommentsComments can be added to explain the JavaScript, or to make it more readable.Single line comments start with //.This example uses single line comments to explain the codeUsing Comments to Prevent ExecutionIn this example the comment is used to prevent the execution of a single code lineIn this example the comments is used to prevent the execution of multiple code linesUsing Comments at the End of a line of workIn this example the comment is placed at the end of a lineVariables are containers for storing information.Declaring (Creating) JavaScript VariablesCreating variables in JavaScript is most often referred to as declaring variables.You can sustain back JavaScript variables with the var statement aft(prenominal) the declaration shown above, the variables are empty (they have no cheri shs yet).However, you can also assign values to the variables when you declare themAfter the execution of the statements above, the variable x will hold the value 5, and carname will hold the value Volvo.Note When you assign a text value to a variable, use quotes around the value.Assigning Values to Undeclared JavaScript VariablesIf you assign values to variables that have not yet been declared, the variables will automatically be declared.These statementshave the same effect asRedeclaring JavaScript VariablesIf you redeclare a JavaScript variable, it will not lose its original value.After the execution of the statements above, the variable x will still have the value of 5. The value of x is not reset (or cleared) when you redeclare it.Conditional StatementsVery often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this.In JavaScript we have the following conditional statementsif statement - us e this statement if you want to execute some code only if a specified condition is trueif...else statement - use this statement if you want to execute some code if the condition is true and another code if the condition is falseif...else if....else statement - use this statement if you want to select one of many blocks of code to be executed trade in statement - use this statement if you want to select one of many blocks of code to be executedscript type=text/javascript//If the time is less than 10,//you will get a frank morning greeting.//Otherwise you will get a Good day greeting.var d = new Date()var time = d.getHours()if (time document.write(Good morning)elsedocument.write(Good day)The JavaScript Switch StatementYou should use the switch statement if you want to select one of many blocks of code to be executed.syntax//You will receive a different greeting based//on what day it is. Note that Sunday=0,//Monday=1, Tuesday=2, etc.var d=new Date()theDay=d.getDay()switch (theDay)case 5document.write(Finally Friday)breakcase 6document.write(Super Saturday)breakcase 0document.write(Sleepy Sunday)breakdefaultdocument.write(Im sounding forward to this weekend)JavaScript Popup BoxesAlert BoxAn alert thump is often used if you want to make sure information comes through to the user.When an alert box pops up, the user will have to click OK to proceed.SyntaxConfirm BoxA confirm box is often used if you want the user to verify or accept something.When a confirm box pops up, the user will have to click either OK or Cancel to proceed.If the user clicks OK, the box returns true. If the user clicks Cancel, the box returns false.SyntaxPrompt BoxA prompt box is often used if you want the user to input a value before entering a page.When a prompt box pops up, the user will have to click either OK or Cancel to proceed after entering an input value.If the user clicks OK the box returns the input value. If the user clicks Cancel the box returns null.SyntaxJavaScript FunctionsJa vaScript FunctionsTo keep the browser from executing a script when the page loads, you can put your script into a function.A function contains code that will be executed by an event or by a call to that function.You may call a function from anywhere within the page (or even from other pages if the function is embedded in an external .js file).Functions can be defined both in the and in the section of a document. However, to assure that the function is read/loaded by the browser before it is called, it could be wise to put it in the section.How to Define a FunctionThe syntax for creating a function is
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.