当我根据用户ID重新加载页面时,我正在即时尝试在线。为此,我正在做
<body>
<iframe frameBorder="0" id="res" src="" height="500" width="500" onload="doit()"></iframe>
</body>
<script>
function doit(){
var t = location.search.split('=')[1]; // get userid from the current page
document.getElementById('res').src="./profile/?id="+t;
}
</script>
但问题是由于onload,它将继续递归查询/profille/?id={id}
。我需要在刚加载身体后一次触发onload。怎么可能?
答案 0 :(得分:0)
添加标志以保存加载状态
<script>
var loaded = false;
function doit(){
if (loaded) return;
var t = location.search.split('=')[1]; // get userid from the current page
document.getElementById('res').src="./profile/?id="+t;
loaded = true;
}
</script>