Difference between window.history.back & parent.history.back

I worked on a website where I need to return to the page I visited. I used parent.history.back. And one of my friends suggested using window.history.back rather than parent.history.back. I'm still confusing the difference. I hope I can get the exact difference between the two.

Thank you in advance

+6
source share
3 answers

window refers to the current frame, and parent refers to the parent of the current frame.

So use window in the usual context. Using a parent when working with iframes

If you do not have an <iframe> , go to window.history.back()

+7
source

window.history.go , the parameter can be either a number that goes to the URL at a certain position (-1 returns to one page, 1 goes to forward one page) or a string. The string must be a partial or full URL, and the function will jump to the first URL that matches the string.

For instance:

 window.history.go(-2) - go back two pages: window.history.go(1) - go forward one page 

parent.history.back () acts like a simple return button. The result is the same as if you clicked on the back button of the browser. There is no parameter to be passed. it is never forwarded like window.history

+2
source

I am sure they are the same. I played with the story honestly, and it seems to be related to the browser window, i.e. You get the same result if you go back (or go) to the root window or to any iframe below it.

Actually, you can get some strange behavior when you have several iframes where returning to one iframe can change one of the other iframes in the window, because it really calls the top window.history.back() .

0
source

All Articles