Nhận tiêu đề trang hiện tại JavaScript
Trong bài viết này, chúng ta sẽ tìm hiểu cách lấy tiêu đề và URL đầy đủ của một tài liệu trong JavaScript với sự trợ giúp của các ví dụ Show
Javascript HTML DOM đã cung cấp một số phương thức cơ bản để truy cập và thao tác với dữ liệu HTML. Để tìm tiêu đề và URL của tài liệu, JavaScript đã cung cấp tài liệu. tiêu đề và tài liệu. URL tương ứng Tài liệu. thuộc tính tiêu đề - Tài liệu. thuộc tính title trả về tiêu đề hiện tại của tài liệu. Thuộc tính này áp dụng cho HTML, SVG, XUL và các tài liệu khác. Cú pháp để lấy tiêu đề của tài liệu được hiển thị bên dưới document.title Tài liệu. thuộc tính url - Thuộc tính chỉ đọc URL của giao diện Tài liệu trả về URL đầy đủ của tài liệu. tôi. e. , vị trí của tài liệu dưới dạng chuỗi, bao gồm giao thức (http. //). Nó tương tự như vị trí thuộc tính Window Object. href trả về URL của trang hiện tại. Cú pháp để lấy URL đầy đủ của tài liệu được hiển thị bên dưới document.URL or document.documentURI Chúng ta hãy xem một số ví dụ cho những điều này - ví dụ 1Sử dụng tài liệu. tài sản tiêu đề Sau đây là một chương trình ví dụ về cách lấy tiêu đề của tài liệu How to know the Title and URL of document in JavaScript Khi thực thi đoạn mã trên, đầu ra sau được tạo ví dụ 2Khi chúng tôi gán một văn bản cho tài liệu. tiêu đề, tiêu đề của tài liệu được thay đổi. Chức năng này được thể hiện trong ví dụ sau Tiêu đề hiện tại của tài liệu có thể được lấy hoặc thay đổi bằng cách sử dụng tài liệu. thuộc tính tiêu đề. Khi xuất hiện, giá trị của is used by default.You can change or get the current title of the document using the document.title attribute. By providing a new title as a string to this attribute, the page's title can be changed. The chosen title will immediately be reflected in the website's title. In this article you will see two types of methods used to change or use Document.title() use in JavaScript
SyntaxFollowing is the syntax of document.title property newPageTitle = 'The title has changed!'; document.title = newPageTitle; ValueA string with the title of the document in it. It includes the value of document.title if the title was modified by setting it. If not, the markup-specified title is present. The new title of the paper is newTitle. The assignment has an impact on the document's return value. title, the title that is published for the document, such as in the window or tab's titlebar, as well as having an impact on the page's DOM, such as the content of the Example 1Before proceeding further let us understand how Document.title is written to execute in this example. Note − You can see the changed title on browser. Example 2Using the document.title property − In this example let us understand how to use javascript to dynamically change a document's title.
|