So While I'm still unclear of what you're trying to get to with this and your question was rather unclear (in retrospect), I was curious about how can we solve this without creating an infinite loop.
window.top !== window.self
won't work because they are one and the same, so I figured that will use a hash on the original page, omit it from the child to differentiate one from its own clone.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
</head>
<body>
<h1 id="h1"></h1>
<script type="text/javascript">
document.getElementById('h1').textContent = window.location.search;
</script>
<script type="text/javascript">
if (window.location.hash === '#origin') {
var ifr = document.createElement('iframe');
var props = {
src: window.document.location.href + '?r=0',
width: 500,
height: 300,
style: "border:1px solid red;width:500px;height:300px;"
}
for (var key in props) {
ifr.setAttribute(key, props[key]);
}
document.body.appendChild(ifr);
setInterval(function(){
var s = ifr.src.split('?r=')[0];
ifr.setAttribute('src', s + '?r=' + parseInt( Math.random() * 1000000))
console.log(ifr.src);
// you can skip this, but it illustrates the refreshes
document.getElementById('h1').textContent = ifr.src;
}, 2000);
}
</script>
</body>
</html>
You will have to run this on your own, the code snippet dislikes its attempt for redirect and I cannot disagree..., - NB: only ran it in Chrome, but there's much that should be different elsewhere
Also, just for the sake of clarity, if you save this as test.html
then you should run it as path/to/your/file/test.html?r=378426#origin