First, Window.top
The top property returns the topmost ancestor window.
This property returns a read-only reference to a top-level window. If the window itself is a top-level window, the top property holds a reference to the window itself. If the window is a frame, then the top property references the top-level window that contains the frame.
Second, window.self
The Self property returns a read-only reference to the window itself. Equivalent to the Window property.
Third, window.location
The Window.location (MDN) object is used to obtain the address (URL) of the current page and redirect the browser to a new page.
3.1 Example
window.location = ' http://www.mazey.net/'; The site will jump to the following URL
3.2 Properties
- Location.hostname returns the domain name of the web host
- Location.pathname returns the path and file name of the current page
- Location.port returns the port of the web host (80 or 443)
- Location.protocol returns the Web protocol used (HTTP///https://)
Iv. examples of IFRAME
V. SummaryIf you want the page to jump out of the IFRAME and add the following code.
if (window.top!== window.self) {//If the window itself is not equal to the top-level window window.top.location.href = window.self.location.href;// Top-level window jumps to its own window}
JavaScript jumps out of the IFRAME frame
JavaScript jumps out of the IFRAME frame