First of all my project has quite tough restrictions:
- offline availability
- as simple coding as possible
=> PHP and other languages are not an option - only html and javascript.
Structure:
- index.html
- frame.html
The index.html contains:
- an simple iframe:
< iframe width="100%" height="100%" src="frame.html" frameborder="0">
< /iframe>
- JavaScript for disabling right mouse clicks:
< script language="javascript"> document.onmousedown=disableclick;
status="Right Click Disabled"; function disableclick(event) {
if(event.button==2) {
alert("TEST");
return false; } }
< /script>
- Another JavaScript for detecting when the user is not active:
< script> var timeoutID; function setup() {
this.addEventListener("mousemove", resetTimer, false);
this.addEventListener("mousedown", 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(); } setup(); function startTimer() {
// wait X seconds before calling goInactive
timeoutID = window.setTimeout(goInactive, 3000); } function resetTimer(e) {
window.clearTimeout(timeoutID);
goActive(); } function goInactive() {
// do something
alert("TIMEOUT");
return false; } function goActive() {
// do something
startTimer(); }
< /script>
- The css-file also contains some restrictions for the mouse cursor:
body {
background-color: #f0f0f0;
cursor: none !important;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none; user-select: none;
}
=> This works quite well for the index.html - but not for the iframe (which is at the moment a local file in the same directory, but it should also be able to link on a website).
I have tried several workarounds but none of them worked while keeping the website in the iframe alive (so that you can also browse through the content of the frame.html).
I am open to any solution - if it hands over the scripts to the child or if the child gets the scripts from the parent or any overlay solution. If there is a workaround for the iframe redirecting on an offline file in the same directory - this would be fine for the first moment.
Thank you very much in advance!
EDIT:
Still got problems with this - it comes to a neverending loop:
$('iframe').load(function(){
$(this).contents().find("body").mousemove(function(){
var timeoutID;
function setup() {
this.addEventListener("mousemove", resetTimer, false);
this.addEventListener("mousedown", 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();
}
setup();
function startTimer() {
timeoutID = (this).setTimeout(goInactive, 4000);
}
function resetTimer(e) {
(this).clearTimeout(timeoutID);
goActive();
}
function goInactive() {
alert("TIMEOUT");
return false;
goactive;
}
function goActive() {
startTimer();
}
});
});
$('iframe').attr("src","JavaScript:'iframe content'");