I am new to JavaScript and after reading related books for quite some time, I am still confused about what is the meaning and what is the function of window.parent? Appreciate if someone could show me some simple samples to let me know what does window.parent mean? Thanks!
Here is the code I am confused, and it is a part of JavaScript code written by an ASP.NET class as a part of the response to client-side. I am especially confused about what means window.parent." + Taget + ".location = '" + url. Appreciate if anyone could make it clear.
HttpContext.Current.Response.Write("<script>window.parent." + Taget + ".location = '" + url + "?userID=" + userID + "';window.location='Title.aspx';</script>");
Thanks in advance,
George
window.parentrefers to a frame’s (or iframe’s) parent:In the above example, if
window.parentwere executed in frame_a.aspx, it would refer to the window containing the <frameset> element.Target refers to either a frame (by name) or a standard target:
_blank– New window_parent– Current frame’s parent_top– Top-most frame (entire browser window/tab)_topand_parentonly refer to different things if your frames are more than one level deep (eg. if frame_a.htm contained another frameset or iframe)'window.parent.' + target + '.location'is changing the URL of a frame, contained within the current frame’s parent, with the name represented by the variabletarget. (I have assumedtagetis simply a typo).In my above example, if frame_a.aspx executed your example code with the
targetvariable “frameB”, it would change the url of that frame to something else (without affecting frameA).Although you haven’t mentioned it, it’s possible you are using
window.openand are trying to change the location on the window that opened it. In that case, you are looking forwindow.opener.