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

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.

%d