Movatterモバイル変換


[0]ホーム

URL:


  1. Tecnologia Web para desenvolvedores
  2. HTML: Linguagem de Marcação de Hipertexto
  3. Referência HTML
  4. Elementos HTML
  5. <iframe>

Esta página foi traduzida do inglês pela comunidade.Saiba mais e junte-se à comunidade MDN Web Docs.

View in EnglishAlways switch to English

<iframe>

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨julho de 2015⁩.

* Some parts of this feature may have varying levels of support.

OelementoHTML<iframe> (ouelemento HTMLinline frame) representa um contexto de navegação aninhado, efetivamente incorporando outra página HTML para a página atual. Em HTML 4.01, um documento pode conter uma cabeça e um corpo ou uma cabeça e um conjunto de quadros, mas não tanto um corpo e um conjunto de quadros. No entanto, um <iframe> pode ser usado dentro de um corpo de documento normal. Cada contexto de navegação tem sua própria história de sessão e o documento ativo. O contexto de navegação que contém o conteúdo incorporado é chamado o pai de contexto de navegação. O contexto de navegação de nível superior (que não tem um pai) normalmente é a janela do navegador.

  • Content categoriesFlow content,phrasing content, embedded content, interactive content, palpable content.
  • Permitted content Special, see prose
  • Tag omission Nenhuma, tanto a tag inicial quanto a final são obrigatórias.
  • Permitted parent elements Any element that accepts embedded content.
  • DOM interfaceHTMLIFrameElement

Atributos

Este elemento inclui osatributos globais.

alignDeprecated

O alinhamento deste elemento em relação ao contexto.

allowfullscreen

Esse atributo pode ser definido como true se o quadro é permitido para ser colocado em modo de tela cheia, chamando seu método deelement.mozRequestFullScreen(). Se isto não estiver definido, o elemento não pode ser colocado em modo de tela cheia.

frameborder

O valor 1 (o padrão) pede ao navegador para desenhar uma borda entre este quadro e todos os outros quadros. O valor 0 informa ao navegador para não traçar uma fronteira entre este quadro e outros quadros.

height

Indica a altura do quadro HTML 5 em pixels CSS, ou HTML 4 em pixels ou porcentagem.

longdesc

Uma URI de uma longa descrição do quadro. Devido à má utilização generalizada, isto não é útil para navegadores não-visuais.

marginheight

A quantidade de espaço em pixels entre o conteúdo do quadro e suas margens superior e inferior.

marginwidth

A quantidade de espaço em pixels entre o conteúdo dos quadros e suas margens direita e esquerda.

mozallowfullscreenNão padrãoDeprecated

Useallowfullscreen ao invés. Em Gecko 9.0 or later, this attribute can be set totrue if the frame is allowed to be placed into full screen mode by calling itselement.mozRequestFullScreen() method. If this isn't set, the element can't be placed into full screen mode.

webkitallowfullscreenNão padrãoDeprecated

Useallowfullscreen ao invés. No Chrome 17 ou mais novo (e talvez mais antigo), this attribute can be set totrue if the frame is allowed to be placed into full screen mode by calling itselement.webkitRequestFullScreen() method. If this isn't set, the element can't be placed into full screen mode.

mozappNão padrão

For frames hosting anopen web app, this specifies the URL of theapp manifest. This ensures that the app is loaded with the right permissions. SeeUsing the Browser API for details. Available in Gecko 13.0 and later.

mozbrowserNão padrão

Indicates that the frame is to appear like a top-level browser window to the embedded content. This means thatwindow.top,window.parent,window.frameElement, etc. willnot reflect the frame hierarchy. This allows for a web browser UI to be implemented entirely with web technology, given the right permissions. SeeUsing the Browser API for details. Available in Gecko 13.0 and later.

name

A name for the embedded browsing context (or frame). This can be used as the value of thetarget attribute of an<a> or<form> element, or the formtarget attribute of an<input> or<button> element.

remoteNão padrão

Carrega a página doframe em um processo separado.

scrolling

Enumerated attribute indicating when the browser should provide a scroll bar (or other scrolling device) for the frame:

  • auto: Só quando necessário.
  • yes: Sempre mostrar uma barra de rolagem.
  • no: Nunca mostrar uma barra de rolagem.
sandbox

If specified as an empty string, this attribute enables extra restrictions on the content that can appear in the inline frame. The value of the attribute can either be an empty string (all the restrictions are applied), or a space-separated list of tokens that lift particular restrictions. Valid tokens are:

  • allow-same-origin: Allows the content to be treated as being from its normal origin. If this keyword is not used, the embedded content is treated as being from a unique origin.
  • allow-top-navigation: Allows the embedded browsing context to navigate (load) content to the top-level browsing context. If this keyword is not used, this operation is not allowed.
  • allow-forms: Allows the embedded browsing context to submit forms. If this keyword is not used, this operation is not allowed.
  • allow-popups: Allows popups (like from window.open).
  • allow-scripts: Allows the embedded browsing context to run scripts (but not create pop-up windows). If this keyword is not used, this operation is not allowed.
  • allow-pointer-lock: Allows the embedded browsing context to use thePointer Lock API.

Nota:

  • When the embedded document has the same origin as the main page, it is strongly discouraged to use bothallow-scripts andallow-same-origin at the same time, as that allows the embedded document to programmatically remove thesandbox attribute. Although it is accepted, this case is no more secure than not using thesandbox attribute.
  • Sandboxing in general is only of minimal help if the attacker can arrange for the potentially hostile content to be displayed in the user's browser outside a sandboxediframe. It is recommended that such content should be served from aseparate dedicated domain, to limit the potential damage.
  • Thesandbox attribute is not supported in Internet Explorer 9 and earlier versions, or in Opera.
seamless

ThisBoolean attribute indicates that the browser should render the inline frame in a way that makes it appear to be part of the containing document, for example by applying CSS styles that apply to the<iframe> to the contained document before styles specified in that document, and by opening links in the contained documents in the parent browsing context (unless another setting prevents this). In XHTML, attribute minimization is forbidden, and the seamless attribute must be defined as<iframe seamless="seamless">.

src

The URL of the page to embed.

srcdoc

The content of the page that the embedded context is to contain. This attribute is expected to be used together with the sandbox and seamless attributes. If a browser supports thesrcdoc attribute, it will override the content specified in thesrc attribute (if present). If a browser does NOT support thesrcdoc attribute, it will show the file specified in thesrc attribute instead (if present).

width

Indicates the width of the frame HTML 5 in CSS pixels, or HTML 4 in pixels or as a percentage.

Scripting

Inline frames, like<frame> elements, enter thewindow.frames pseudo-array.

From the DOMiframe element, scripts can get access to thewindow object of the included HTML page via thecontentWindow property. ThecontentDocument property refers to the document element inside theiframe (this is equivalent tocontentWindow.document), but is not supported by Internet Explorer versions before IE8.

From the inside of a frame, a script can get a reference to the parent window viawindow.parent.

Scripts trying to access a frame's content are subject to thesame-origin policy, and cannot access most of the properties in the other window object if it was loaded from a different domain. This also applies to a script inside a frame trying to access its parent window. Cross-domain communication can still be achieved withwindow.postMessage.

Exemplo 1

html
<script>  var iframe = window.getElementsByTagName("iframe")[0];  alert("Frame title: " + iframe.contentWindow.title);</script><iframe src="page.html" width="300" height="300">  <p>Your browser does not support iframes.</p></iframe>

Exemplo 2: Open link inside iframe in another tab

html
<base /><iframe  width="400"  height="215"  frameborder="0"  scrolling="no"  marginheight="0"  marginwidth="0"  src="https://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=es-419&amp;geocode=&amp;q=buenos+aires&amp;sll=37.0625,-95.677068&amp;sspn=38.638819,80.859375&amp;t=h&amp;ie=UTF8&amp;hq=&amp;hnear=Buenos+Aires,+Argentina&amp;z=11&amp;ll=-34.603723,-58.381593&amp;output=embed"></iframe><br /><small>  <a    href="https://maps.google.com/maps?f=q&amp;source=embed&amp;hl=es-419&amp;geocode=&amp;q=buenos+aires&amp;sll=37.0625,-95.677068&amp;sspn=38.638819,80.859375&amp;t=h&amp;ie=UTF8&amp;hq=&amp;hnear=Buenos+Aires,+Argentina&amp;z=11&amp;ll=-34.603723,-58.381593"   >    See bigger map  </a></small>

Resultado

Live example

Notas

Nota:Starting in Gecko 6.0, rendering of inline frames correctly respects the borders of their containing element when they're rounded usingborder-radius.

Especificações

Specification
HTML
# the-iframe-element

Compatibilidade dos navegadores

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp