Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the global length variable (window.length)?

Tags:

javascript

I have just observed that every page has length global variable.

What does this variable represent? Is it somehow related to how many iframes/frames are loaded on page?

It'd be happy if a doc reference is provided.


For example, on Chrome new tab page its value is 17 and here, on StackOverflow it is 0.

like image 543
Ionică Bizău Avatar asked Oct 27 '14 15:10

Ionică Bizău


2 Answers

Yes, it's how many frames (including iframes) are in the current window:

https://developer.mozilla.org/en-US/docs/Web/API/Window.length

W3 specification:

http://www.w3.org/html/wg/drafts/html/master/browsers.html#accessing-other-browsing-contexts

like image 60
danmullen Avatar answered Nov 15 '22 19:11

danmullen


window.length

Returns the number of frames (either frame or iframe elements) in the window.

Example

if (window.length) {
  // this is a document with subframes
}

MDN Reference

Note: No part of this answer comes from me. It all comes from the referred source.

like image 40
Hanky Panky Avatar answered Nov 15 '22 19:11

Hanky Panky