What is the Difference between window.location.href and top.location.href in JavaScript?


Grammarly

More than 40 Lakhs Students and Professionals use Grammarly for their spell and grammar checks. You can register and try for free.

Sometimes, you might be using the JavaScript to get the current location of the page. You might come across 2 properties

  • window.location.href
  • top.location.href

What is the Difference between window.location.href and top.location.href in JavaScript?

The window.location.href will return the location of the current page.

The top.location.href will return the location of the topmost window in the heirarchy. This can be generally be useful when using the frames etc.


Grammarly

More than 40 Lakhs Students and Professionals use Grammarly for their spell and grammar checks. You can register and try for free.
%d bloggers like this: