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.

8
  • 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". Commented Oct 27, 2014 at 15:34
  • 1
    @IonicăBizău Downvote as, per the downvote mouseover, "this question does not show any research effort".
    – admdrew
    Commented Oct 27, 2014 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
    Commented Oct 27, 2014 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
    Commented Oct 27, 2014 at 15:37
  • 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
    Commented Oct 27, 2014 at 15:47

2 Answers 2

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

3
  • 5
    Can you site a more credible source (not the downvoter)
    – Patsy Issa
    Commented Oct 27, 2014 at 15:31
  • 5
    FYI, W3schools is not thought of too highly around here due to a number of inaccuracies.
    – Jonathan M
    Commented Oct 27, 2014 at 15:32
  • @PatsyIssa Wow, my bad! Corrected.
    – admdrew
    Commented Oct 27, 2014 at 15:39
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.

1
  • Weird example, given window.length is not protected. Commented Oct 27, 2014 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.