Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> HTML

HTML DOM Location reload() method


วิธีการโหลดตำแหน่ง HTML DOM ใหม่ () ใช้สำหรับสร้างเอกสารปัจจุบันอีกครั้ง มีฟังก์ชันการทำงานเหมือนกับปุ่มโหลดซ้ำในเบราว์เซอร์

ไวยากรณ์

ต่อไปนี้เป็นไวยากรณ์ -

location.reload(forceGetParameter)

พารามิเตอร์

ที่นี่ “forceGetParameter” สามารถเป็นดังต่อไปนี้ -

forceGetParameter รายละเอียด
จริง กำหนดว่าเอกสารปัจจุบันถูกโหลดซ้ำจากเซิร์ฟเวอร์
เท็จ กำหนดว่าเอกสารปัจจุบันถูกโหลดซ้ำจากแคชของเบราว์เซอร์

ตัวอย่าง

ให้เราดูตัวอย่างสำหรับ 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">Password: </label>
<input type="password" id="passSelect"><br>
<input type="button" onclick="doReload()" value="Reload">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var emailSelect = document.getElementById("emailSelect");
   var passSelect = document.getElementById("passSelect");
   divDisplay.textContent = 'Do not reload, all the details will be lost';
   function doReload(){
      alert('Page reloaded, all the details are lost');
      location.reload();
   }
</script>
</body>
</html>

ผลลัพธ์

สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

ก่อนคลิก 'โหลดซ้ำ' ปุ่ม −

HTML DOM Location reload() method

คลิก 'โหลดซ้ำ' ปุ่มหลังจากกรอกรายละเอียด -

HTML DOM Location reload() method