sams javascript phrasebook, essential code and commands (2006)

273 447 0
sams javascript phrasebook, essential code and commands (2006)

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

[...]... message with JavaScript on local pages Including JavaScript Code Including JavaScript Code window.alert(“Welcome to JavaScript! ”); JavaScript code can come in two ways: either embedded into an HTML page, or in an external file.The most common way to include JavaScript code is to use the element.You can place this element anywhere, and the code is then... that supports JavaScript and has it activated Executing JavaScript with Event Handlers WARNING: When the code after the javascript: URL prefix returns something, the result is printed to the screen Usually, this is not desirable You can use the special JavaScript function void() to avoid this: javascript: void (code_ that_would_return_something()); Executing JavaScript with Event Handlers ... following fashion: However, this is completely bogus—what else if not JavaScript code could be the value of an event handler attribute? Therefore, omit the javascript: and just provide the code to be executed when the associated event is fired Coping with Browsers without JavaScript document.write("Welcome to JavaScript! "); ... Date and Time Information Creating a Random Number var rand = min + Math.floor((max – min + 1) * Math.random()); The random() method of the Math object calculates a pseudo-random number between 0 and 1 (excluding) However, usually you are interested in a random number between, say, 1 and 10.With a small mathematical calculation, this can be achieved For the example, multiply the result of Math.random()... Therefore, these HTML comments are not necessary any longer Using External JavaScript Files Especially when you are reusing JavaScript code on your website, an external JavaScript file (or several files) comes in handy.This external file contains only the JavaScript code, no elements A element is, however, used to... JavaScript function showText() { window.alert("Welcome to JavaScript! "); } 15 16 CHAPTER 1 JavaScript Basics Using a JavaScript Event Handler (event.html) WARNING: It is a common misconception that the javascript: URL prefix must be used with event handlers, in the... chapters Understanding JavaScript (and Its History) JavaScript is a client-side scripting language—that means a language that runs on the client side, within a web browser (JavaScript can also be used on the server side and otherwise outside a browser, but this is not of interest for the purpose of this book.) If the browser supports the language, JavaScript grants access to the current page and lets the... onload=”showText();”> The third way to execute JavaScript code (the first two ones being elements and javascript: pseudo URLs) is via en event handler Most HTML elements support a few events; for instance, the tag supports the load element Using the on prefix, code can be attached to this event (more options are covered in Chapter 6, “OOP and Events”).Therefore, the following code runs the showText() function... Garrett coined the acronym, and since then, the whole web world seems to have gone crazy And although AJAX can be explained in a couple of minutes actually, it requires a good knowledge of various aspects of JavaScript. This explains the growing demand for advanced JavaScript content, and also led to the writing of the JavaScript Phrasebook When we (Damon Jordan, Mark Taber, and I) created the book series... page intentionally left blank 1 JavaScript Basics T his chapter covers some basics regarding JavaScript It does not explicitly cover the language syntax itself— this is covered in enough tutorials and books and does not fit into the phrasebook concept However, fundamentals such as putting JavaScript code in a page are explained in detail Also, a bit of JavaScript history and browser war stories are used . y0 w0 h0" alt="" Sams Publishing, 800 East 96th Street, Indianapolis, Indiana 46240 USA Christian Wenz JavaScript ™ DEVELOPER’S L IBRARY PHRASEBOOK ESSENTIAL CODE AND COMMANDS JavaScript Phrasebook Copyright. Contents Introduction 1 1 JavaScript Basics 5 Understanding JavaScript (and Its History) 5 Setting Up a Test System 7 Configuring Web Browsers 9 Including JavaScript Code 11 Using External JavaScript Files. JavaScript Files 12 Dynamically Loading JavaScript Files 13 Using JavaScript Pseudo URLs 14 Executing JavaScript with Event Handlers 15 Coping with Browsers without JavaScript 16 2 Common Phrases 19 Detecting

Ngày đăng: 28/04/2014, 17:05

Từ khóa liên quan

Mục lục

  • Table of Contents

  • Introduction

  • 1 JavaScript Basics

    • Understanding JavaScript (and Its History)

    • Setting Up a Test System

    • Configuring Web Browsers

    • Including JavaScript Code

    • Using External JavaScript Files

    • Dynamically Loading JavaScript Files

    • Using JavaScript Pseudo URLs

    • Executing JavaScript with Event Handlers

    • Coping with Browsers without JavaScript

    • 2 Common Phrases

      • Detecting the Browser Type

      • Checking Browser Capabilities

      • Preventing Caching

      • Redirecting the Browser

      • Reloading the Page

      • Creating a Random Number

      • Date and Time Information

      • Searching with Regular Expressions

      • Replacing Text

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan