I built a website using PHP & JavaScript and also I built an android WebView activity each page in website have a activity in android i'm trying to setTimeout in JavaScript 10 sec and this timeout will update when user clicked anywhere on screen , JavaScript code :
var timer = null;
timer = timerAction();
$(window).click(function () {
clearTimeout(timer);
timer = timerAction();
});
function timerAction() {
return setTimeout(function () {
showToast("Timeout relogin agagin");
loadNewPage('LoginActivity');
}, 10000);
}
and my android code to going another page :
#JavascriptInterface
public void loadeNewPage(String page) {
if (page.equalsIgnoreCase("MainMenuActivity")) {
Intent intent = new Intent(context, MainMenuActivity.class);
finish();
startActivity(intent);
}
}
my problem , example : if i clicked 10 times on screen timeout it will called 10 times again .
i know its bit late anyway please go through this , it may help you
function Timeout(fn, interval)
{
var id = setTimeout(fn, interval);
this.cleared = false;
this.clear = function () {
this.cleared = true;
clearTimeout(id);
};
}
var t = new Timeout(function ()
{
console.log("Cleared function");
t.clear();
showToast("Timeout relogin again");
loadNewPage('LoginActivity');
}, 5000);
$(window).click(function () {
if (t.cleared)
{
t = new Timeout(function ()
{
console.log("Cleared function");
t.clear();
showToast("Timeout relogin again");
loadNewPage('LoginActivity');
}, 5000);
}
else {
console.log("one time out funtion already running ");
}
});
Related
I am trying to do a kiosk application. In this application, if index page opened with post values (index.html?location=5) except index page with no post value and any action happened in 60 seconds like mouse over or typing, redirect to index page with no value. I am using this code but..
function setIdle(cb, seconds) {
var timer;
var interval = seconds * 1000;
function refresh() {
clearInterval(timer);
timer = setTimeout(cb, interval);
};
$(document).on('keypress, click', refresh);
$(document).on('mouseover', refresh);
var parts = location.pathname.split('/');
if(parts[parts.length - 1] != 'index.html') {
location.href = 'index.html';
}
refresh();
}
setIdle(function() {
location.href = './index.html';
}, 60);
When I run this code, it is refreshing index page with no value. I can not figure it out how can I do that ?
I want to do
if index.html?location = 5 wait for 60 seconds for any mouse or keyboard action then return index.html
if index.html do not check mouse or keyboard
setIdle() gets called only once (when the page first loads), and this is where your conditional logic is. refresh() is what's actually doing the redirect, but this is not inside any sort of if, and so it gets called every single time regardless of which page you're on.
Why not ignore the idle function completely if the page is index.html?
function setIdle(cb, seconds) {
var timer;
var interval = seconds * 1000;
function refresh() {
clearInterval(timer);
timer = setTimeout(cb, interval);
};
$(document).on('keypress, click', refresh);
$(document).on('mouseover', refresh);
refresh();
}
var parts = location.pathname.split('/');
//If page is not index.html
if(parts[parts.length - 1] != 'index.html') {
//initialize the "idle" functionality
setIdle(function() {
location.href = './index.html';
}, 60);
}
I want to create a JavaScript function, which should popup an alert when the user starts typing in the TextBox and the server couldn't retrieve the results in 3 seconds even though it contain the results.
My current code:
function keyup(e) {
if(timeout != null) {
clearTimeout(timeout);
timeout = null;
}
if(jq('.ui-menu-item').is(":visible")) {
time = performaceTiming.responseStart;
timeout = setTimeout(bluff, 3000);
}
else {
timeout = setTimeout(popup, 2000);
}
}
function bluff() {
alert('alert box inside bluff');
}
function popup() {
alert('the requested name could not be found, please search for other name');
}
you don't call the functions named bluff or popup but the undefined variables, you should add () to call the function
if(jq('.ui-menu-item').is(":visible")){
time=performaceTiming.responseStart;
timeout=setTimeout(bluff(),3000);}
else{
timeout=setTimeout(popup(),2000);
}
There is a countdown in a page. And i want to bypass or speed it up.
Is there a possibility to run add ticket function from chrome's console or something?Or can I change the xtime variable to something like 2-3 seconds.Or directly call the add ticket function?
jQuery(document).ready(function($){
var xTime=120;
$("#ticketTimer").html(xTime);
var myVar = setInterval(
function(){
if(typeof checkAdBlock === 'undefined')
{
document.getElementById("compt").innerHTML = "<b>you use an AdBlocker!</b> To win a ticket, <b>Desactivate AdBlock and reload the page.</b>";
return false;
}
else if(xTime>0)
{
xTime--;
$("#ticketTimer").html(xTime);
}
else
{
addTicket();
clearInterval(myVar);
}
},
1000);
});
I have a function that checks the status of connection to server. I want to run checkOnline every 5 seconds. If the connection is lost, and it keeps failing then the fadeIn for error message keeps running as well (creates a flashing effect). How can I change it so that the fade functions are only run once, when it fails, but still keeps checking the connection.
$(function () {
var url = 'https://examplesite.com/';
function checkOnline() {
$.get(url).done(function () {
window.location = url;
}).fail(function () {
$('.errortext').hide().fadeIn(500);
$('.loadingtext').fadeOut(500);
});
};
window.setInterval(function () { checkOnline(); }, 5000);
setTimeout(function () { checkOnline(); }, 2000);
});
Keep track of whether the fade effects already ran. Then check it before running the fade. Here's an example that uses a variable called fadeFlag:
var fadeFlag = false;
function fadeOnce() {
// Has fade happened already?
if (fadeFlag === false) {
// No. Then do the effects
$('.errortext').hide().fadeIn(500);
$('.loadingtext').fadeOut();
fadeFlag = true;
}
}
function checkOnline() {
$.get(url).done(function () {
window.location = url;
}).fail(function () {
// Try the fade effects
fadeOnce();
});
};
The first time fadeOnce() is called, it runs the effects and then sets fadeFlag to true. The next time, it sees that fadeFlag is true, so it does nothing.
I have an AS2 Flash SWF that is calling another AS2 Flash File using loadMovieNum("flash.swf",2) and a JavaScript file that calls a function on page using a timer. This is what I get in Firefox with Flash 10 (IE8 gives no error message):
uncaught exception: Error calling
method on NPObject! [plugin exception:
Error in Actionscript. Use a try/catch
block to find error.].
What is going wrong? I can't see a problem. It is suppose to clear the contents of the embedded swf and use a Flash alert dialog to confirm Yes or No.
Flash:
import flash.external.ExternalInterface;
import mx.controls.Alert;
System.security.allowDomain("mydomain.com");
function getTimeOut()
{
// Show alert dialog box
_level2._visible = false;
Alert.show("You are about to Timeout. Do you want to continue using Courseware?", "Timeout", Alert.YES |
Alert.NO, this, myClickHandler);
}
ExternalInterface.addCallback("timeOut", this, getTimeOut);
this.onMouseDown = function(){
//if not on login
getURL("javascript:startTimer();");
};
var myClickHandler:Function = function (evt_obj:Object) {
switch (evt_obj.detail) {
case Alert.YES :
getURL("javascript:buttonEvent('yes');");
break;
case Alert.NO :
getURL("javascript:buttonEvent('no');");
break;
}
_level2._visible = true;
};
//load courseware
loadMovieNum("embedded.swf",2);
JavaScript:
<script type="text/javascript">
// <![CDATA[
var so = new SWFObject("main.swf", "mainMovie", "100%", "100%", "9", "#083770");
so.addParam("scale", "noscale");
so.addParam("quality", "high");
so.addParam("allowScriptAccess","always");
so.write("flashcontent");
var timerMin = '<?php echo($timerMinutes); ?>';
var timer;
var timer2;
function startTimer()
{
var timerMill = 0;
clearTimeout(timer);
timerMill = getMillis();
timer = setTimeout ( 'stopTimer()', timerMill );
}
function stopTimer()
{
clearTimeout(timer);
timer2 = setTimeout( 'redirectPage()', 60000);
//call flash function
getFlashMovie("mainMovie").timeOut();
}
function buttonEvent(evt)
{
if(evt == 'yes')
{
clearTimeout(timer2);
startTimer();
}
else
{
clearTimeout(timer2);
redirectPage();
}
}
function getMillis()
{
var milliseconds = 300000;
if(timerMin == parseInt(timerMin))
{
//convert to milliseconds
//60000 milliseconds in 1 minute
milliseconds = (parseInt(timerMin)) * 60000;
}
return milliseconds;
}
function getFlashMovie(movieName)
{
var isIE = navigator.appName.indexOf("Microsoft") != -1;
return (isIE) ? window[movieName] : document[movieName];
//return document.getElementById(movieName);
}
function redirectPage()
{
top.location = "timeout.php?t=<?php echo($timerMinutes); ?>";
}
// ]]>
</script>
Same old story - NPObject.
I took Flash out of the picture and was able to achieve the same thing using CSS and JavaScript. The fix for this is to create a policy file for Flash but for something so simple I just went another direction so not to debug.