Skip to content

Commit 6406a55

Browse files
committed
Browser environment, specs
1 parent 3c4c432 commit 6406a55

2 files changed

Lines changed: 53 additions & 50 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ sftp-config.json
2121
Thumbs.db
2222

2323

24+
branch_structure.json
25+
temp_auto_push.bat
26+
temp_interactive_push.bat
Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,113 @@
1-
# Browser environment, specs
1+
# Môi trường trình duyệt, các thông số kỹ thuật
22

3-
The JavaScript language was initially created for web browsers. Since then it has evolved and become a language with many uses and platforms.
3+
Ngôn ngữ JavaScript được tạo ra với mục đích ban đầu là dành cho những trình duyệt web. Kể từ đó nó đã tiến hoá và trở thành một ngôn ngữ có nhiều công dụng và nền tảng.
44

5-
A platform may be a browser, or a web-server or another *host*, even a "smart" coffee machine, if it can run JavaScript. Each of them provides platform-specific functionality. The JavaScript specification calls that a *host environment*.
5+
Một nền tảng có thể là trình duyệt, máy chủ web hoặc một *máy chủ* khác, hoặc là cả một máy pha cà phê *thông minh*, nếu nó có thể chạy bằng JavaScript. Mỗi một nền tảng cung cấp chức năng mang tính riêng biệt. Việc đặc tả của JavaScript gọi đó là *môi trường máy chủ*.
66

7-
A host environment provides own objects and functions additional to the language core. Web browsers give a means to control web pages. Node.js provides server-side features, and so on.
7+
Môi trường máy chủ cung cấp các đối tượng và các hàm riêng bổ sung cho lõi của ngôn ngữ. Trình duyệt web cung cấp phương tiện để kiểm soát các trang web. Node.js cung cấp các tính năng từ phía máy chủ, v.v.
88

9-
Here's a bird's-eye view of what we have when JavaScript runs in a web browser:
9+
Đây là cái nhìn toàn cảnh về những gì chúng ta có khi JavaScript chạy trong trình duyệt web:
1010

1111
![](windowObjects.svg)
1212

13-
There's a "root" object called `window`. It has two roles:
13+
Có một đối tượng "gốc" được gọi là `cửa sổ`. Nó có hai vai trò:
1414

15-
1. First, it is a global object for JavaScript code, as described in the chapter <info:global-object>.
16-
2. Second, it represents the "browser window" and provides methods to control it.
15+
1. Đầu tiên, nó là một đối tượng chung cho mã JavaScript, như được mô tả trong chương <info:global-object>.
16+
2. Thứ hai, nó đại diện cho "cửa sổ trình duyệt" và cung cấp các phương thức để kiểm soát nó.
1717

18-
For instance, here we use it as a global object:
18+
Ví dụ, ở đây chúng ta sử dụng nó như một đối tượng toàn cục:
1919

2020
```js run
2121
function sayHi() {
22-
alert("Hello");
22+
alert("Xin chào");
2323
}
2424

25-
// global functions are methods of the global object:
25+
// các hàm toàn cục là các phương thức của đối tượng toàn cục:
2626
window.sayHi();
2727
```
2828

29-
And here we use it as a browser window, to see the window height:
29+
Còn ở đây thì chúng ta sử dụng nó làm cửa sổ trình duyệt, để xem chiều cao của cửa sổ:
3030

3131
```js run
32-
alert(window.innerHeight); // inner window height
32+
alert(window.innerHeight); // chiều cao bên trong của cửa sổ
3333
```
3434

35-
There are more window-specific methods and properties, we'll cover them later.
35+
Có nhiều phương thức và thuộc tính dành riêng cho cửa sổ hơn, chúng ta sẽ đề cập đến chúng sau.
3636

3737
## DOM (Document Object Model)
3838

39-
Document Object Model, or DOM for short, represents all page content as objects that can be modified.
39+
Mô hình đối tượng tài liệu hoặc viết tắt là DOM, thể hiện tất cả nội dung trang dưới dạng các đối tượng có thể được sửa đổi.
4040

41-
The `document` object is the main "entry point" to the page. We can change or create anything on the page using it.
41+
Đối tượng `document` là "điểm vào" chính của trang. Chúng ta có thể thay đổi hoặc tạo bất cứ thứ gì trên trang bằng cách sử dụng nó.
4242

43-
For instance:
43+
Ví dụ:
4444
```js run
45-
// change the background color to red
45+
// thay đổi màu nền thành màu đỏ
4646
document.body.style.background = "red";
4747

4848
// change it back after 1 second
4949
setTimeout(() => document.body.style.background = "", 1000);
5050
```
5151

52-
Here we used `document.body.style`, but there's much, much more. Properties and methods are described in the specification: [DOM Living Standard](https://dom.spec.whatwg.org).
52+
Ở đây chúng ta đã sử dụng `document.body.style`, nhưng còn nhiều hơn thế nữa. Các thuộc tính và phương thức được mô tả trong thông số kỹ thuật: [Tiêu chuẩn cơ bản của DOM](https://dom.spec.whatwg.org).
5353

54-
```smart header="DOM is not only for browsers"
55-
The DOM specification explains the structure of a document and provides objects to manipulate it. There are non-browser instruments that use DOM too.
54+
```smart header="DOM không chỉ dành cho trình duyệt"
55+
Việc đặc tả DOM giải thích cấu trúc của tài liệu và cung cấp các đối tượng để thao tác với nó. Có những công cụ không có trình duyệt cũng sử dụng DOM.
5656
57-
For instance, server-side scripts that download HTML pages and process them can also use DOM. They may support only a part of the specification though.
57+
Ví dụ: các tập lệnh phía máy chủ tải xuống các trang HTML và xử lý chúng cũng có thể sử dụng DOM. Tuy nhiên, chúng có thể chỉ hỗ trợ một phần thông số kỹ thuật.
5858
```
5959

60-
```smart header="CSSOM for styling"
61-
There's also a separate specification, [CSS Object Model (CSSOM)](https://www.w3.org/TR/cssom-1/) for CSS rules and stylesheets, that explains how they are represented as objects, and how to read and write them.
60+
```smart header="CSSOM cho việc thiết kế"
61+
Ngoài ra còn có một thông số kỹ thuật riêng, [Mô hình đối tượng CSS (CSSOM)](https://www.w3.org/TR/cssom-1/) dành cho các quy tắc và biểu định kiểu CSS, giải thích cách chúng được thể hiện dưới dạng đối tượng và cách đọc và viết chúng.
6262
63-
CSSOM is used together with DOM when we modify style rules for the document. In practice though, CSSOM is rarely required, because we rarely need to modify CSS rules from JavaScript (usually we just add/remove CSS classes, not modify their CSS rules), but that's also possible.
63+
CSSOM được sử dụng cùng với DOM khi chúng tôi sửa đổi quy tắc kiểu cho tài liệu. Tuy nhiên, trên thực tế, CSSOM hiếm khi được yêu cầu vì chúng ta hiếm khi cần sửa đổi các quy tắc CSS từ JavaScript (thông thường chúng ta chỉ thêm/xóa các lớp CSS chứ không sửa đổi các quy tắc CSS của chúng), nhưng điều đó cũng có thể thực hiện được.
6464
```
6565

6666
## BOM (Browser Object Model)
6767

68-
The Browser Object Model (BOM) represents additional objects provided by the browser (host environment) for working with everything except the document.
68+
Mô hình đối tượng trình duyệt (BOM) đại diện cho các đối tượng bổ sung được cung cấp bởi trình duyệt (môi trường máy chủ) để làm việc với mọi thứ ngoại trừ tài liệu.
6969

70-
For instance:
70+
Ví dụ:
7171

72-
- The [navigator](mdn:api/Window/navigator) object provides background information about the browser and the operating system. There are many properties, but the two most widely known are: `navigator.userAgent` -- about the current browser, and `navigator.platform` -- about the platform (can help to differ between Windows/Linux/Mac etc).
73-
- The [location](mdn:api/Window/location) object allows us to read the current URL and can redirect the browser to a new one.
72+
- Đối tượng [navigator](mdn:api/Window/navigator) cung cấp thông tin cơ bản về trình duyệt và hệ điều hành. Có nhiều thuộc tính, nhưng hai thuộc tính được biết đến rộng rãi nhất là: `navigator.userAgent` -- về trình duyệt hiện tại và `navigator.platform` -- về nền tảng (có thể giúp phân biệt giữa Windows/Linux/Mac, v.v.).
73+
- Đối tượng [location](mdn:api/Window/location) cho phép chúng ta đọc URL hiện tại và có thể chuyển hướng trình duyệt sang một URL mới.
7474

75-
Here's how we can use the `location` object:
75+
Đây là cách chúng ta có thể sử dụng đối tượng `location`:
7676

7777
```js run
78-
alert(location.href); // shows current URL
79-
if (confirm("Go to Wikipedia?")) {
80-
location.href = "https://wikipedia.org"; // redirect the browser to another URL
78+
alert(location.href); // hiển thị URL hiện tại
79+
if (confirm("Truy cập vào Wikipedia?")) {
80+
location.href = "https://wikipedia.org"; // chuyển hướng trình duyệt đến một URL khác
8181
}
8282
```
8383

84-
Functions `alert/confirm/prompt` are also a part of BOM: they are directly not related to the document, but represent pure browser methods of communicating with the user.
84+
Các chức năng `cảnh báo/xác nhận/nhắc nhở` cũng là một phần của BOM: chúng không liên quan trực tiếp đến tài liệu nhưng thể hiện các phương thức giao tiếp thuần túy của trình duyệt với người dùng.
8585

86-
```smart header="Specifications"
87-
BOM is the part of the general [HTML specification](https://html.spec.whatwg.org).
86+
```smart header="Những đặc tả"
87+
BOM là một phần của [đặc tả HTML] chung(https://html.spec.whatwg.org).
8888
89-
Yes, you heard that right. The HTML spec at <https://html.spec.whatwg.org> is not only about the "HTML language" (tags, attributes), but also covers a bunch of objects, methods and browser-specific DOM extensions. That's "HTML in broad terms". Also, some parts have additional specs listed at <https://spec.whatwg.org>.
89+
Có, bạn nghe nói rằng ngay. Thông số HTML tại <https://html.spec.whatwg.org> không chỉ nói về "ngôn ngữ HTML" (thẻ, thuộc tính) mà còn bao gồm một loạt đối tượng, phương thức và tiện ích mở rộng DOM dành riêng cho trình duyệt. Đó là "HTML theo nghĩa rộng". Ngoài ra, một số bộ phận còn có thông số kỹ thuật bổ sung được liệt kê tại <https://spec.whatwg.org>.
9090
```
9191

92-
## Summary
92+
## Tóm tắt
9393

94-
Talking about standards, we have:
94+
Nói về tiêu chuẩn, chúng ta có:
9595

96-
DOM specification
97-
: Describes the document structure, manipulations and events, see <https://dom.spec.whatwg.org>.
96+
Đặc tả DOM
97+
: Mô tả cấu trúc tài liệu, các thao tác và sự kiện, xem <https://dom.spec.whatwg.org>.
9898

99-
CSSOM specification
100-
: Describes stylesheets and style rules, manipulations with them and their binding to documents, see <https://www.w3.org/TR/cssom-1/>.
99+
Đặc tả CSSOM
100+
: Mô tả các bảng định kiểu và quy tắc kiểu, các thao tác với chúng và ràng buộc của chúng với tài liệu, xem <https://www.w3.org/TR/cssom-1/>.
101101

102-
HTML specification
103-
: Describes the HTML language (e.g. tags) and also the BOM (browser object model) -- various browser functions: `setTimeout`, `alert`, `location` and so on, see <https://html.spec.whatwg.org>. It takes the DOM specification and extends it with many additional properties and methods.
102+
Đặc tả HTML
103+
: Mô tả ngôn ngữ HTML (ví dụ: thẻ) và cả BOM (mô hình đối tượng trình duyệt) -- các chức năng trình duyệt khác nhau: `setTimeout`, `alert`, `location`, v.v., xem <https://html.spec.whatwg .org>. Nó lấy đặc tả DOM và mở rộng nó với nhiều thuộc tính và phương thức bổ sung.
104104

105-
Additionally, some classes are described separately at <https://spec.whatwg.org/>.
105+
Ngoài ra, một số lớp được mô tả riêng tại <https://spec.whatwg.org/>.
106106

107-
Please note these links, as there's so much stuff to learn it's impossible to cover and remember everything.
107+
Vui lòng lưu ý các liên kết này, vì có quá nhiều thứ cần học nên không thể trình bày và ghi nhớ hết mọi thứ.
108108

109-
When you'd like to read about a property or a method, the Mozilla manual at <https://developer.mozilla.org/en-US/search> is also a nice resource, but the corresponding spec may be better: it's more complex and longer to read, but will make your fundamental knowledge sound and complete.
109+
Khi bạn muốn đọc về một thuộc tính hoặc một phương thức, hướng dẫn sử dụng Mozilla tại <https://developer.mozilla.org/en-US/search> cũng là một tài nguyên hay, nhưng thông số kỹ thuật tương ứng có thể tốt hơn: nó phức tạp hơn và dài hơn để đọc, nhưng sẽ làm cho kiến ​​thức cơ bản của bạn trở nên rõ ràng và đầy đủ.
110110

111-
To find something, it's often convenient to use an internet search "WHATWG [term]" or "MDN [term]", e.g <https://google.com?q=whatwg+localstorage>, <https://google.com?q=mdn+localstorage>.
111+
Để tìm thứ gì đó, thường rất thuận tiện khi sử dụng tìm kiếm trên internet "WHATWG [thuật ngữ]" hoặc "MDN [thuật ngữ]", ví dụ: <https://google.com?q=whatwg+localstorage>, <https://google.com?q=mdn+localstorage>.
112112

113-
Now we'll get down to learning DOM, because the document plays the central role in the UI.
113+
Bây giờ chúng ta sẽ bắt đầu tìm hiểu DOM vì tài liệu này đóng vai trò trung tâm trong giao diện người dùng.

0 commit comments

Comments
 (0)