Phương thức in cửa sổ JavaScript []
Cải thiện bài viết
Lưu bài viết
Thích bài viết
- Cập nhật lần cuối. 02 tháng 12 năm 2022
Cải thiện bài viết
Lưu bài viết
Phương thức in cửa sổ JavaScript [] là một mã đơn giản trong JavaScript được sử dụng để in nội dung của các trang web.
- Phương thức print[] in nội dung của cửa sổ hiện hành
- Về cơ bản, nó sẽ mở hộp thoại In cho phép bạn chọn giữa các tùy chọn in khác nhau
cú pháp.
window.print[]
Thông số. Không có tham số được yêu cầu
Trả về. Hàm này không trả về bất cứ thứ gì
Mã Javascript sau hiển thị một nút in và sau đó nó hiển thị thuộc tính của trang web đó trong một trang tính mà bạn sẽ in trang đó.
Cửa sổ hàm in JavaScript. print[] được sử dụng ở đây để thực hiện chức năng.
Thí dụ.
HTML
HI GEEKSFORGEEKS USER'S
window.print[];2__
Sử dụng truy vấn phương tiện để cải thiện bố cục
Phát hiện yêu cầu in
Trình duyệt gửi các sự kiện
9 và DOCTYPE html>
JavaScript Window Close Example
function popup title[] {
const my_window = window.open[
"",
"mywindow",
"status=1,width=350,height=150"
];
my_window.document.write["Print Me"];
my_window.document.write[''];
my_window.document.write[
"When you print this window, it will close afterward.
"
];
my_window.document.write[""];
}
To try out the afterprint event, click the link below to open
the window to print. You can also try changing the code to use
beforeprint to see the difference.
Open Popup Window
0 để nội dung xác định thời điểm in có thể đã xảy ra. Bạn có thể sử dụng điều này để điều chỉnh giao diện người dùng được trình bày trong quá trình in [chẳng hạn như bằng cách hiển thị hoặc ẩn các thành phần giao diện người dùng trong quá trình in]ví dụ
Dưới đây là một số ví dụ phổ biến
Mở và tự động đóng cửa sổ bật lên khi hoàn tất
Nếu bạn muốn có thể tự động đóng cửa sổ bật lên [ví dụ: phiên bản tài liệu thân thiện với máy in] sau khi người dùng in nội dung của nó, bạn có thể sử dụng mã như sau
DOCTYPE html>
JavaScript Window Close Example
function popup title[] {
const my_window = window.open[
"",
"mywindow",
"status=1,width=350,height=150"
];
my_window.document.write["Print Me"];
my_window.document.write[''];
my_window.document.write[
"When you print this window, it will close afterward.
"
];
my_window.document.write[""];
}
To try out the afterprint event, click the link below to open
the window to print. You can also try changing the code to use
beforeprint to see the difference.
Open Popup Window
Xem ví dụ trực tiếp
In một trang bên ngoài mà không cần mở nó
Nếu bạn muốn có thể in một trang bên ngoài mà không cần mở nó, bạn có thể sử dụng một
DOCTYPE html>
JavaScript Window Close Example
function popup title[] {
const my_window = window.open[
"",
"mywindow",
"status=1,width=350,height=150"
];
my_window.document.write["Print Me"];
my_window.document.write[''];
my_window.document.write[
"When you print this window, it will close afterward.
"
];
my_window.document.write[""];
}
To try out the afterprint event, click the link below to open
the window to print. You can also try changing the code to use
beforeprint to see the difference.
Open Popup Window
1 ẩn [xem. HTMLIFrameElement], tự động xóa nó sau khi người dùng in nội dung của nó. Sau đây là một ví dụ có thể sẽ in một tệp có tên DOCTYPE html>
JavaScript Window Close Example
function popup title[] {
const my_window = window.open[
"",
"mywindow",
"status=1,width=350,height=150"
];
my_window.document.write["Print Me"];
my_window.document.write[''];
my_window.document.write[
"When you print this window, it will close afterward.
"
];
my_window.document.write[""];
}
To try out the afterprint event, click the link below to open
the window to print. You can also try changing the code to use
beforeprint to see the difference.
Open Popup Window
2