Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

275
Visualizações
Use of $(parent.window).height()

I have a page which will sometimes be loaded in an iframe and sometimes just loaded by itself, depending on certain parameters which are not relevant for the purpose of this question. In both cases I want to get the height of the viewport so am using $(parent.window).height(). This seems to return the correct figure in both cases (in and out of an iframe), but I just wanted to check if there is any potential pitfall using $(parent.window).height() in a page which is not in an iframe - i.e. the page technically has no parent.

Otherwise I can structure an if..else with $(parent.window).height() and $(window).height() for in and out of an iframe respectively, but is is necessary? Can I just use $(parent.window).height() to cover both cases?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

The docs say that

If a window does not have a parent, its parent property is a reference to itself.

So you're good, window.parent will be a reference to the parent, if one exist, if not, it's a reference to the current window.
There's no need for a condition to check if the window actually has a parent to use the window.parent property, as long as it doesn't matter that it could be the current window that is returned.

over 4 years ago · Santiago Trujillo Relatório

0

You can use window.top to refer to the topmost window. Whether a page is opened normally, or in a frame, or in a nested frame, it will always refer to the top window.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda