Skip to content

Instantly share code, notes, and snippets.

@AlbertoMonteiro
Last active April 30, 2016 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlbertoMonteiro/b525001263efcceb7f6cd9bb86a15b9d to your computer and use it in GitHub Desktop.
Save AlbertoMonteiro/b525001263efcceb7f6cd9bb86a15b9d to your computer and use it in GitHub Desktop.
Blocked a frame with origin
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
<h1>This is a IFrame</h1>
</div>
</body>
<script src="file.js"></script>
</html>
document.domain = "s3-website-sa-east-1.amazonaws.com";
window.alberto = {
nome: "Alberto",
idade: 26,
seApresentar: function() {
alert("Ola eu sou " + this.nome + " e tenho " + this.idade + " anos.")
}
};
setTimeout(function () {
var parent = window.parent;
parent.doAlert(window.alberto);
var h1Title = document.querySelectorAll("h1")[0];
h1Title.style = "color: red";
h1Title.textContent = "A mensagem foi enviada para a window.parent";
}, 2000)
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script src="file.js"></script>
</head>
<body>
<div>
<h1>This page hosts a IFrame</h1>
<hr />
<iframe src="http://crossiframesample2.s3-website-sa-east-1.amazonaws.com/" frameborder="1"></iframe>
</div>
</body>
</html>
document.domain = "s3-website-sa-east-1.amazonaws.com";
window.doAlert = function (pessoa) {
pessoa.seApresentar();
var h1Title = document.querySelectorAll("h1")[0];
h1Title.style = "color: red";
h1Title.textContent = "Pessoa recebida: " + pessoa.nome;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment