I was working on a website, where I need to go back to the page which I visited. I was using parent.history.back. And one of my friend suggested rather use window.history.back instead of parent.history.back. I'm still confused the difference. I hope I can get the exact difference between them.
Thanks in advance
Window History Back back() method loads the previous URL in the history list. This is the same as clicking the Back button in the browser.
So using javascript:history. back() introduces a small risk that can be exploited by phishing attacks. Just use explicit links to pages instead of relying on browser history.
The history.go() method loads a URL (page) from the history list. The history.go() method only works if the page exist in the history list.
The length property returns the number of URLs in the history list of the current browser window. The property returns at least 1, because the list includes the current page. This property is useful to find out how many pages the user has visited in the current browsing session.
window
refers to the current frame, while parent
refers the parent of the current frame.
So, use window
in normal context. Use parent when dealing with iframes
If you don't have any <iframe>
then go with window.history.back()
window.history.go has the parameter can either be a number which goes to the URL within the specific position (-1 goes back one page, 1 goes forward one page), or a string. The string must be a partial or full URL, and the function will go to the first URL that matches the string.
For example:
window.history.go(-2) - go back two pages:
window.history.go(1) - go forward one page
parent.history.back() acts like a simple back button. The result is equal as if you clicked on the back browser button. There is have no parameter to be passed. it never forward like window.history
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With