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

255
Visualizações
allow-same-origin doesn't allow me to access properties of top object

I have the following code in the page example1.com:

<iframe src='//example2.com/embed.html' sandbox="allow-same-origin allow-modals allow-scripts allow-top-navigation allow-top-navigation-by-user-activation">

And I have the following code in my embed.html

<script>
    try { 
        document.write('top url: ' + top.location.href)
    }
catch (e) { 
document.write('error' + e);

}
</script>

I get the error:

SecurityError: Blocked a frame with origin "https://example2.com" from accessing a cross-origin frame.

I only want to get properties of top object and I use the tag allow-same-origin in my iframe code. Doesn't this tag allow me to run the iframe as same-origin? If not, why do we have that tag?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

example1.com and example2.com are a different domains therefore you have an issue with CORS (Cross-Origin Resource Sharing), but not with Content Security Policy. CORS allows direct access between the same domains or domain and its subdomain only.
You cannot get top.location.href property inside of cross origin iframe, but you can set it: top.location.href = 'https://any_domain.com/path.html' if allow-top-navigation presents in the sandox attribute or if sandbox is absent.

The sandbox attribute cannot help to bypass CORS restrictions, it only can imposes additional restrictions on the capabilities inside the iframe.

You can use window.postMessage() method for cross-origin communication between a page and an iframe embedded within it.

about 4 years ago · Juan Pablo Isaza 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