Difference between [removed].href and top.location.href

后端 未结 4 1949
轮回少年
轮回少年 2020-11-27 11:34

Can Anyone tell me the difference between window.location.href and top.location.href ?

And also where to use which one.

And which

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 11:42

    top object makes more sense inside frames. Inside a frame, window refers to current frame's window while top refers to the outermost window that contains the frame(s). So:

    window.location.href = 'somepage.html'; means loading somepage.html inside the frame.

    top.location.href = 'somepage.html'; means loading somepage.html in the main browser window.

    Two other interesting objects are self and parent.

提交回复
热议问题