Posts

Showing posts from May, 2024

JAVASCRIPT Window location.replace () new URL method

Image
JAVASCRIPT Window location.replace () new URL method explained JAVASCRIPT Window location.replace () new URL method The window.location.replace() method is used in JavaScript to replace the current document with a new one. This method changes the URL of the current window to the URL specified in the parameter, and the new document replaces the current document in the history list. This means that after using location.replace() , the current page will not be stored in the session history, so the user will not be able to use the back button to navigate back to it. Here is the basic JavaScript syntax for using location.replace() : window.location.replace("http://www.new-url.com"); Key Characteristics No History Entry:   The main difference between location.replace() and location.href is that location.replace() does not create a new entry in the browser's history. Therefore, the user cannot navigate back to the previous page using the back button. Same-origin Policy:  Th...

Javascript location reload method true

Image
Javascript location reload method true  In JavaScript , you can reload the current page using the location.reload() method. If you want to ensure that the page is reloaded from the server (and not from the cache), you can pass true as an argument. Here’s how you do it: location.reload(true); Here's a brief explanation: location.reload(): This method reloads the current URL, similar to how the refresh button works in the browser. true: When true is passed as an argument, it forces the page to reload from the server, bypassing the cache. ExampleTo force a reload from the server, you can use the following code: // This will reload the page from the server location.reload(true); If you don’t need to bypass the cache, you can call location.reload() without any arguments or with false: // This will reload the page and might use the cache location.reload(); This is useful for ensuring the user always gets the most up-to-date content.