Sunday, February 11, 2024

Automatic Page Refresh with JavaScript

 1) Run this code in the Chrome browser console

Right-click on the newtab/window and select "Inspect" or simply press Ctrl + Shift + I (Windows/Linux) or Cmd + Opt + I (Mac) to open the Chrome Developer Tools.

In the Developer Tools, navigate to the "Console" tab.

Copy and paste the provided JavaScript code into the console.

Press Enter to execute the below code.

2) Code is as below

bypramod = window.open("http://www.bypramod.blogspot.com");
timer1 = setInterval(function() {
    bypramod.location.href = "http://www.bypramod.blogspot.com";
}, 5000); // 5000 milliseconds (5 seconds) interval
 

Explanation:

bypramod = window.open("http://www.bypramod.blogspot.com");: This line opens a new browser window or tab with the specified URL ("http://www.bypramod.blogspot.com") and assigns it to the variable bypramod. The window.open() method is commonly used to open a new browser window or tab via JavaScript.

timer1 = setInterval(function() { bypramod.location.href = "http://www.bypramod.blogspot.com"; }, 5000);: This line sets up an interval that triggers a function at regular intervals. In this case, the function is responsible for changing the location (URL) of the bypramod window/tab to "http://www.bypramod.blogspot.com". The interval is set to 5000 milliseconds, which is equivalent to 5 seconds.

setInterval() is a JavaScript function that repeatedly calls a provided function at specified time intervals.

The provided function inside setInterval() is an anonymous function (a function without a name) that changes the href property of the bypramod window/tab, effectively refreshing the content by loading the specified URL.

---


Note:

The timing interval may be too short (every second). Some websites or servers may restrict frequent requests to prevent abuse. 


***


No comments:

Post a Comment