কম্পিউটার

জাভাস্ক্রিপ্টে window.location.href, window.location.replace এবং window.location.assign এর মধ্যে পার্থক্য?


উইন্ডো অবজেক্ট জাভাস্ক্রিপ্টে অবস্থান অবজেক্ট অন্তর্ভুক্ত করে। এটি নিম্নলিখিত বৈশিষ্ট্যগুলি অন্তর্ভুক্ত করে -

window.location.href

এটি বর্তমান পৃষ্ঠার URL প্রদান করে৷

উদাহরণ

<!DOCTYPE html>
<html>
   <body>
      <p>Click below to get the complete URL of the page.</p>
      <button onclick = "display()">URL</button>
      <script>
         function display() {
            var res = location.href;
            document.write(res);
         }
      </script>
   </body>
</html>

window.location.replace

এটি বর্তমান নথি প্রতিস্থাপন করতে ব্যবহৃত হয়৷

উদাহরণ

<!DOCTYPE html>
<html>
   <body>
      <button onclick = "display()">Replace current document</button>
      <script>
         function display() {
            location.replace("https://www.qries.com")
         }
      </script>
   </body>
</html>

window.location.assign

আপনি যদি একটি নতুন নথি লোড করতে চান, তাহলে JavaScript অ্যাসাইন ব্যবহার করুন৷

উদাহরণ

<!DOCTYPE html>
<html>
   <body>
      <button onclick = "display()">Open new document</button>
      <script>
         function display() {
            location.assign("https://www.qries.com")
         }
      </script>
   </body>
</html>

  1. পিএইচপি এবং জাভাস্ক্রিপ্টের মধ্যে পার্থক্য

  2. HTML এ একটি আইডি এবং ক্লাসের মধ্যে পার্থক্য

  3. HTML এবং HTML 5 এর মধ্যে পার্থক্য

  4. HTML এবং ASP এর মধ্যে পার্থক্য।