Activity Forums Salesforce® Discussions Difference between window.parent.location and window.top.location in salesforce?

  • Vikas Kumar

    Member
    January 31, 2017 at 1:48 pm

    Hi Sushant,

    window.location.href returns the location of the current page.

    top.location.href (which is an alias of window.top.location.href) returns the location of the topmost window in the window hierarchy. If a window has no parent, top is a reference to itself (in other words, window === window.top).

    top is useful both when you're dealing with frames and when dealing with windows which have been opened by other pages.

  • nick

    Member
    September 12, 2017 at 6:20 am

    Both are different, window.location is an object containing the property while location.href which is a string. The window.location is an object that holds all information about current document location (host, href, port, protocol etc.). The location.href is shorthand for window.location.href, and this is only string with full url to current website. The location object's toString() value is the same as the href property, so they are identical if used as strings. Setting window.location is the same as setting window.location.href.

    <script language="javascript" type="text/javascript">

    window.location.href = "http://www.example.com";

    </script>

     

    The above Javascript code sets the new href (URL) for the current window.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos