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

Phương thức reload() của Location trong HTML DOM

Phương thức reload() của Location trong HTML DOM được dùng để tải lại (render lại) tài liệu hiện tại. Nó cung cấp chức năng tương tự nút tải lại (reload) trên trình duyệt.

Cú pháp

location.reload(forceGetParameter)

Tham số

forceGetParameter có thể là:

forceGetParameterChi tiết
trueĐịnh nghĩa tài liệu hiện tại được tải lại từ máy chủ (server).
falseĐịnh nghĩa tài liệu hiện tại được tải lại từ bộ nhớ cache trình duyệt.

Ví dụ

Ví dụ minh họa phương thức Location reload():

<!DOCTYPE html> <html> <head> <title>Location reload()</title> <style> form { width:70%; margin: 0 auto; text-align: center; } * { padding: 2px; margin:5px; } input[type="button"] { border-radius: 10px; } </style> </head> <body> <form> <fieldset> <legend>Location-reload()</legend> <label for="urlSelect">Email: </label> <input type="email" id="emailSelect"><br> <label for="urlSelect">Mật khẩu: </label> <input type="password" id="passSelect"><br> <input type="button" onclick="doReload()" value="Tải lại"> <div id="divDisplay"></div> </fieldset> </form> <script> var divDisplay = document.getElementById("divDisplay"); var emailSelect = document.getElementById("emailSelect"); var passSelect = document.getElementById("passSelect"); divDisplay.textContent = 'Không tải lại, mọi chi tiết sẽ mất'; function doReload(){ alert('Trang đã tải lại, tất cả chi tiết đều mất'); location.reload(); } </script> </body> </html>

Kết quả

Trước khi nhấn nút 'Tải lại':

Phương thức reload() của Location trong HTML DOM

Nhấn nút 'Tải lại' sau khi điền chi tiết:

Phương thức reload() của Location trong HTML DOM