close

[Solved] location.reload(true) is deprecated

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error location.reload(true) is deprecated in javascript. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How To Solve location.reload(true) is deprecated Error ?

  1. How To Solve location.reload(true) is deprecated Error?

    To Solve location.reload(true) is deprecated Error You can use location.reload() without the forceReload flag. This is just deprecated because it is not in the spec

  2. location.reload(true) is deprecated

    To Solve location.reload(true) is deprecated Error You can use location.reload() without the forceReload flag. This is just deprecated because it is not in the spec

Solution 1

You can use location.reload() without the forceReload flag. This is just deprecated because it is not in the spec: https://www.w3.org/TR/html50/browsers.html#dom-location-reload

Solution 2

If you look at interface definition for Location you will see the following:

/**
  * Reloads the current page.
  */
reload(): void;
/** @deprecated */
reload(forcedReload: boolean): void;

Using location.reload() is the valid syntax. It is only the reload with forcedReload which is deprecated.

In your case changing location.reload(true) to location.reload() to resolve your issue.

Solution 3

Since window.location.reload(true) has been deprecated. You can use:

window.location.href = window.location.href

to force-reload and clear the cache.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment