คุณสมบัติ frames ของ HTML DOM Window ใช้สำหรับคืนค่าอ็อบเจกต์ที่สอดคล้องกับหน้าต่าง แทนเฟรมทั้งหมดที่อยู่ในหน้าต่างนั้น
ไวยากรณ์ (Syntax)
การคืนค่าเฟรมในหน้าต่างปัจจุบัน
window.frames
ตัวอย่างการใช้งาน
ตัวอย่างต่อไปนี้แสดงการใช้งานคุณสมบัติ HTML DOM Window frames:
<!DOCTYPE html><html> <head> <title>HTML DOM Window frames</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-frames</legend> <label>User 1:</label><iframe src="https://www.example.com"></iframe><br> <label>User 2:</label><iframe src="https://www.example.com"></iframe><br> <input type="button" value="Launch Virus" onclick="goToURL()"> <div id="divDisplay"> </div> </fieldset> </form> <script> var divDisplay = document.getElementById("divDisplay"); function goToURL() { for (var i = window.frames.length - 1; i >= 0; i--) window.frames[i].location = "https://www.tutorialspoint.com/html5/foo.mp4"; divDisplay.textContent = 'Virus Deployed'; } </script> </body> </html>
ผลลัพธ์
ก่อนคลิกปุ่ม 'Launch Virus':

หลังคลิกปุ่ม 'Launch Virus':
