9

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.

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
  • Downvoter, do you care to leave a comment...? – Ionică Bizău Oct 27 '14 at 15:34
  • 3
    Sure! I don't think it's that difficult to type "window.length" into a search engine. Since it takes all of about twenty seconds to find the answer if you actually bother, that seems like it fits the criteria for "lacks research effort". – Anthony Grist Oct 27 '14 at 15:34
  • 1
    @IonicăBizău Downvote as, per the downvote mouseover, "this question does not show any research effort". – admdrew Oct 27 '14 at 15:35
  • 2
    @AnthonyGrist But form other hand, the question itself is really good. For example I didn't know that. Now I know, hence OP deserves upvotes. not downvotes. I'm sure many people can learn something from even simplest questions like this one. – dfsq Oct 27 '14 at 15:35
  • 1
    @dfsq, this site is really not intended to answer basic things like this. It specifically allows for downvoting any question that shows no effort in research. We value effort from the person asking the question, rather than them sitting back and saying "feed me." – Jonathan M Oct 27 '14 at 15:37
  • 1
    @dfsq I disagree, but we're all free to vote as we like. I'll downvote a question that's trivially answered by actually searching for the answer before posting on Stack Overflow and you can upvote for posting a question that teaches you something you didn't know. – Anthony Grist Oct 27 '14 at 15:38
  • Well, I appreciate the feedback. Interesting stuff in answers... at least for me. :-) Thanks guys! – Ionică Bizău Oct 27 '14 at 15:44
  • 4
    I don't think I would have ever googled window.length if it wasn't for this question, questions that lack research effort are frowned upon but given the op's rep and github track it seems more of a "here's something interesting" question. – Patsy Issa Oct 27 '14 at 15:47

2 Answers2

15

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

admdrew
  • 3,790
  • 4
  • 27
  • 39
danmullen
  • 2,556
  • 3
  • 20
  • 28
8
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.

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95