Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Cách lấy tiêu đề (title) và URL đầy đủ của tài liệu trong JavaScript


JavaScript HTML DOM cung cấp phương thức cơ bản truy cập/thao tác HTML. Để lấy tiêu đề và URL tài liệu, dùng document.title và document.URL. Thảo luận từng cái.

Tiêu đề tài liệu

Dùng document.title lấy tiêu đề.

Ví dụ

<html> <head> <title>Tutorix</title> </head> <body> <script> document.write("The title of the document is" + " " + document.title); </script> </body> </html>

Kết quả

Tutorix


URL tài liệu

Dùng document.URL lấy URL.

Ví dụ

<html> <body> <script> document.write("The URL of the document is: " + " " + document.URL); </script> </body> </html>

Kết quả

The URL of the document is: https://www.tutorialspoint.com/cg/assets/ovPEzF.php