【发布时间】:2018-05-28 04:54:38
【问题描述】:
我创建了一个网站,在 iframe 中显示了 three.js 模型。每当用户处于非活动状态 x 分钟时,我都会尝试将用户重定向回主页(index.html)。我已经让它与一些 java 脚本一起工作,但问题是它只在我在 iframe 之外处于活动状态时才有效。当我实际旋转模型并与之交互时,它仍然会重定向我。我一直在研究这个并没有找到解决方案。我试过用
调用 iframe 中的函数onload="setup();"
但这并没有奏效,还有很多其他的。这是我的代码,
JavaScript
var timeoutID;
function setup() {
this.addEventListener("mousemove", resetTimer, false);
this.addEventListener("mousedown", resetTimer, false);
this.addEventListener("mouseover", resetTimer, false);
this.addEventListener("mouseout", resetTimer, false);
this.addEventListener("keypress", resetTimer, false);
this.addEventListener("DOMMouseScroll", resetTimer, false);
this.addEventListener("mousewheel", resetTimer, false);
this.addEventListener("touchmove", resetTimer, false);
this.addEventListener("MSPointerMove", resetTimer, false);
startTimer();
}
function startTimer() {
// wait 5 seconds before calling goInactive
timeoutID = window.setTimeout(goInactive, 5000);
}
function resetTimer(e) {
window.clearTimeout(timeoutID);
goActive();
}
function goInactive() {
// do something
window.location = "index.html";
}
function goActive() {
// do something
startTimer();
}
HTML
<main role="main" class="col-md-9 ml-sm-auto col-lg-12 px-0">
<!-- Featured Content -->
<div class="embed-responsive embed-responsive-16by9">
<div id="test">
<iframe style="position:fixed; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%; border:none;
margin:0; padding:0; overflow:hidden; z-index:0;" class="embed-responsive-item" src="models/model.html" onload="setup();" allowfullscreen></iframe>
</div>
</div>
</main>
【问题讨论】:
标签: javascript html iframe responsive-design three.js