Phương thức stop() của đối tượng Window trong HTML DOM cung cấp chức năng dừng tải tài nguyên của một cửa sổ mà không cần nhấn nút dừng của trình duyệt.
Cú pháp
window.stop()
Ví dụ
Ví dụ minh họa phương thức HTML DOM Window stop():
<!DOCTYPE html> <html> <head> <title>HTML DOM Window stop()</title> <style> * { padding: 2px; margin:5px; } form { width:70%; margin: 0 auto; text-align: center; } input[type="button"] { border-radius: 10px; </style> </head> <body> <form> <fieldset> <legend>HTML-DOM-Window-stop( )</legend> <input id="urlSelect" type="url" placeholder="Nhập URL..."><br> <input id="textSelect" type="text" placeholder="Họ tên"><br> <input type="button" value="Đi đến" onclick="openWindow()"> <input type="button" value="Đóng" onclick="closeWindow()"> <input type="button" value="Khôi phục" onclick="restoreWindow()"> <div id="divDisplay"></div> </fieldset> </form> <script> var urlSelect = document.getElementById("urlSelect"); var textSelect = document.getElementById("textSelect"); var winSource; function openWindow() { if(textSelect.value === 'admin'){ browseWindow = window.open(urlSelect.value, "browseWindow", "width=400, height200"); winSource = urlSelect.value; browseWindow.opener.document.getElementById("divDisplay").textContent = "Cửa sổ con hoạt động"; } else { window.stop(); document.getElementById("divDisplay").textContent = "Cửa sổ con đã dừng"; } } function closeWindow(){ if(browseWindow){ browseWindow.close(); browseWindow.opener.document.getElementById("divDisplay").textContent = "Cửa sổ con đã đóng"; } } function restoreWindow(){ if(browseWindow.closed){ browseWindow = window.open(winSource, "browseWindow", "width=400, height=200"); browseWindow.opener.document.getElementById("divDisplay").textContent = "Cửa sổ con đã khôi phục"; } } </script> </body> </html>
Kết quả
Nhấn nút „Đi đến“ với Họ tên không được ủy quyền:

Nhấn nút „Đi đến“ với Họ tên được ủy quyền:
