Can Anyone tell me the difference between window.location.href and top.location.href ?
And also where to use which one.
And which one will be better when redirecting after an ajax call in mvc?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
window.location.hrefreturns the location of the current page.top.location.href(which is an alias ofwindow.top.location.href) returns the location of the topmost window in the window hierarchy. If a window has no parent,topis a reference to itself (in other words,window===window.top).topis useful both when you’re dealing with frames and when dealing with windows which have been opened by other pages. For example, if you have a page calledtest.htmlwith the following script:The resulting alert will have the full path to test.html – not about:blank, which is what
window.location.hrefwould return.To answer your question about redirecting, go with
window.location.assign(url);