w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
setInterval only working inside of if(){} block
The code below is fully functionnal, and looks very much like your non-working example. You can check here : http://jsbin.com/ofezip/1/edit So i guess you have an issue with the scope of your variables. window.onload = function() { var myOutput = document.createElement("output"); document.body.appendChild(myOutput); var t4 = 0; var helloInterval = setInterval(adds,250); function adds(){ if (t4 < 10){ t4++; myOutput.value = "hello " + t4; } else { myOutput.value = "goodbye" ; clearInterval(helloInterval); return; } } };

Categories : Javascript

if statement is not working inside setInterval
Here's a quick solution: <script> $(function() { $("#slideshow > div:gt(0)").hide(); var count = 1; setInterval(function() { $('#slideshow > div:first') .fadeOut(1000, function () { if(count != 1) $(this).css('top', '10px'); count++; }) .next() .fadeIn(1000, function() { if(count != 1) $(this).animate({top: '-100px'}, 1000); if(count == 3) count = 0; }) .end() .appendTo('#slideshow'); }, 3000); }); </script>

Categories : Javascript

setInterval or setTimeout inside an .each loop
Try var tocURL = "../broadcasted.xml"; $.get(tocURL, function(d) { $(d).find('tweet').each(function(index) { var cvdIndexId = $(this).find("index"); var cvdTweetAuthor = $(this).find("author").text(); var cvdTweetDescription = $(this).find("description").text(); setTimeout(function() { if (cvdTweetAuthor === "Animator") { obj = $('#cvd_bubble_left').append(makeCvdBubbleAnimator(cvdIndexId, cvdTweetAuthor, cvdTweetDescription)); obj.fitText(7.4); } else { obj = $('#cvd_bubble_right').append(makeCvdBubble(cvdIndexId, cvdTweetAuthor, cvdTweetDescription)); obj.fitText(7.4); } }, index * 2000); }); }); Demo: Plunker

Categories : Javascript

Javascript setTimeout inside setInterval
I guess your problem is that each time you reload your page with setInterval you are spawning another setTimeout chain, without clearing the previous one. Try saving your timeoutId and clearing it as the first thing in your countdown code. Something like this should work: <? $query=q_return("SELECT nume, cod, data, MINUTE(data_start) as minute, data_start FROM chestionare WHERE data_start>date_sub(now(), interval 2 minute)");?> <script> var timp_c="<?=$query['minute'];?>"; var sec, min, timeoutId; $.get('<?=return_url("php/getimp.php");?>', { k: "sec" } ).done(function(data){sec=data;}); $.get('<?=return_url("php/getimp.php");?>', { k: "min" } ).done(function(data){min=data;}); if (timeoutId) { clearTimout(

Categories : PHP

setInterval() inside plugin function not being called
The problem is this inside the slider function does not point to the object you think it points to. setInterval($.proxy(function () { slide.call(this); }, this), g); Demo: Fiddle or better setInterval($.proxy(slide, this), g); Demo: Fiddle

Categories : Javascript

creating an image inside a setInterval not starting with the same position
Use overflow:hidden for container: .Container { width: 300px; height: 300px; background-color: White; overflow: hidden; border: 1px solid black; } Fiddle Updated fiddle with deleting hided dom elements.

Categories : Javascript

Javascript setInterval doesn't update timestamp used inside
Generate a new date each time instead of always showing the same one : function loadLog(){ var tim = new Date(); document.getElementById('timebox').innerHTML=tim.getTime(); } window.setInterval(loadLog, 1000);

Categories : Javascript

CSS3 transition fails to animate when inside setInterval
Are you looking for something like this? http://jsfiddle.net/dJQ5t/ var selectors = ['div#northSlogan', 'div#eastSlogan', 'div#southSlogan', 'div#westSlogan']; var words = ["list","of","random","words"]; function printWords() { /* populate array with numbers 0 through # of elements in 'words' array */ var nums = []; for (var i=0; i < words.length; i++) {nums[i] = i;} /* fade out all slogan divs */ for(var i=0; i < 4; i++) { $(selectors[i]).removeClass('opaque'); } /* generate random index and fill slogan div with chosen text */ setTimeout(function() { for (var i=0; i < 4; ++i) { var index = Math.floor(Math.random()*nums.length); document.querySelector(selectors[i]).innerHTML = words[nums[index]];

Categories : Javascript

setInterval not working in Opera
I think you are in a corner buggy case. When it's comes to user interface, it's not a good practice to rely on the state of the graphic objects to find out the state of the view. In other terms, you don't want to "read" the state of the view in the HTML elements, but rather in a variable or a set of variables called a view model. I suggest that you rewrite your code this way, and I think there's a good chance to work around the bug: var blinker; function blink(elem) { clearInterval(blinker); var visible = false; blinker = setInterval(function() { visible = !visible; $(elem).css('visibility', visible ? 'visible' : 'hidden'); }, 500); }

Categories : Javascript

setInterval, animating multiple images, stopping setInterval
To the using of setInterval and stopping the animation var animation = setInterval(yourAnimation,500); // run yourAnimation every 500ms clearInterval(animation); // stop animation To the animation var slideShow = ["img1.jpg","img2.jpg", ... ,"img8.jpg"]; var counter = 0; function yourAnimation() {someImage.src = slideShow[++counter%slideShow.length];}

Categories : Javascript

simple setInterval with paper.js not working
The first reason is the extra } you have which is a syntax error. The second reason[s] is that there are errors: Refused to execute script from 'https://raw.github.com/paperjs/paper.js/master/dist/paper.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled. fiddle.jshell.net/miguelrivero/2BzUL/10/show/:1 Uncaught SyntaxError: Unexpected token } fiddle.jshell.net/miguelrivero/2BzUL/10/show/:40 Refused to execute script from 'https://raw.github.com/paperjs/paper.js/master/dist/paper.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled. fiddle.jshell.net/_display/:1 Uncaught SyntaxError: Unexpected token } fiddle.jshell.net/_display/:40 Refused to execute script from 'https://raw.github.com/paperj

Categories : Javascript

JavaScript, setInterval() working beyond its timer
Javascript is single-threaded, so your calls to set interval will be added to a queue. They will execute sequentially, but if your functions take longer than your actual interval you will work beyond the expected finish time of your setInterval calls.

Categories : Javascript

Javascript setInterval not working in Internet Explorer
Absolutely. You are setting the source to what it already is, so it's not actually changing, so no need to update as far as the browser is concerned. To cachebust, just do this: document.getElementById('camA').src = "http://10.0.0.157/jpg/image.jpg?x="+new Date().getTime(); I used Vanilla JS because reasons.

Categories : Javascript

javascript setInterval() working in Dreamweaver but not in Chrome
id is only visible from the scope of the moveDown function. Make it global so that you can call clearInterval(id) in moveUp. Change function moveDown() { var top=-500 var id = setInterval(function() { to var id; function moveDown() { var top=-500 id = setInterval(function() { And changing the dom every tenth of millisecond (.1) might be a little extrem...

Categories : Javascript

Javascript setInterval within setInterval timer increasing
Be concerned with the scope of your variables and clear the blink intervall before initiating a new one. $(document).ready(function() { var refreshRate = 5000; var blink = -1; var autoRefresh = setInterval( function () // Call out to get the time { $.ajax({ type: 'GET', success: function(data){ document.getElementById('data').innerHTML=data; if(blink>-1) clearInterval(blink); blink = setInterval (function () { var blink_cell = $("#blink_div").html(); if (blink_cell > 0) { $("#blink_div").toggleClass("blink"); } else { $("#blink_div").addClass("invisible"); }

Categories : Javascript

Why javascript setTimeout delay is not working and setInterval is too slow
You're calling setTimeout improperly: setTimeout(dibujo, interval); // no () You have to pass a reference to your function, which is accomplished by using the name of the function. You don't want () because that causes the function to be called before the call to setTimeout happens, with the return value of your function passed in instead of a reference to the function.

Categories : Javascript

Jquery SetInterval Not Working Correctly in Chrome and IE but is fine in FireFox
Updated answer: You've updated to say that the problem is you don't see the updated information. You're using HTTP GET, which means that the browser is welcome to cache the result of the call if it likes, unless you specify appropriate cache control headers in the response. Some browsers cache XHR results, others don't. Your best bet is to make the GET return appropriate headers. However, you can also force the GET to bypass cache, using jQuery's cache: false flag on the ajax call. Original answer: You haven't said what it is that "doesn't work," but if it's that you're seeing updates happening at odd intervals, that's not surprising. Your code will start an ajax request roughly once a second (!). That ajax request will complete some time later. How much later will depend entirely

Categories : Internet Explorer

chrome setInterval() for blurred tabs not working correctly, even for periods of 1 second or larger
This timer doesn't lag, because it checks the 'real' time using the Date object. var endTime = new Date; endTime.setMinutes(then.getMinutes()+10); refresh(); function refresh(){ var diff = Math.abs((endTime-new Date().getTime())/1000); document.getElementById("time_left").innerHTML = zeroPad(Math.floor(diff/3600)) + ":" + zeroPad(Math.floor(diff/60))+ ":" + zeroPad(Math.floor((diff%60))); if (new Date < endTime){ setTimeout(refresh,1000); } } // zeroPad method: function zeroPad(nr,base,chr){ var len = (String(base||10).length - String(nr).length)+1; return len > 0? new Array(len).join(chr||'0')+nr : nr; } JsFiddle BTW: using setTimeout has the advantage of being able to stop the timer any time (see al

Categories : Javascript

Javascript, setInterval starts after while loop? how to make it start inside while loop?
What is happening is you are asking the computer to run the nested inner function once per millisecond. And you are asking this to be done ten times in a row, so by the end, the computer should be sending an alert exactly ten thousand times per second. I'm surprised it doesn't consume all the CPU and consume all memory and cause a fatal error. This will continue until you call clearInterval(), or until the window is closed. http://www.w3schools.com/jsref/met_win_setinterval.asp

Categories : Javascript

Using jQuery in Tampermonkey
EDIT: Since Greasemonkey 2.0 you do not (and cannot) use unsafeWindow.jQuery for getting the host page's instance of jQuery. You just use window.jQuery, and // @grant none (or @grant whatever other special APIs you need for non-jQuery things). Sources: https://github.com/greasemonkey/greasemonkey/issues/1952 http://www.greasespot.net/2014/06/greasemonkey-20-release.html Tampermonkey currently (Feb 2015) seems to work similarly by default settings: http://tampermonkey.net/faq.php#Q404 old outdated answer below: Add a directive // @grant unsafeWindow. Also, if you are getting your jQuery reference from the host window object, you won't need the @require line.

Categories : Jquery

Run function from Tampermonkey button
Not sure if you have found a solution to your problem yet, but after many hours of struggling to get a solution that: is easy enough for a beginner (me) portable between Tampermonkey and Greasemonkey and looks like something I might be able to do.... I got this working: function addBtn() { $("#quest_form").each( function () { $(this).before("<input type='button' value='Auto Grind' id='autoGrind'>"); $('autoGrind').click(autoGrind()); } ); } addBtn(); Just four notes regarding this solution: I custom made it for ME, so it might not work perfectly for you I'm VERY new to JS so if I used bad "grammar", I'm sorry. The .each won't be necessary, I had to add LOTS of buttons (removed the code dealing with their ID's

Categories : Javascript

jquery not working on firefox but working on console
Is that button generated on the fly, dynamically ? well, it seems so. If that is the case, then, try using $("button#close").live('click',(function() { disablediv(); }); I faced similar issues before and solved it with this method. Hope it helps !

Categories : Jquery

Force Tampermonkey to run/execute script late
The content you want is being loaded by AJAX, so you need to use AJAX-compensation techniques in your script. The easiest way to do that is to use waitForKeyElements(). Something like: // ==UserScript== // @name _YOUR_SCRIPT_NAME // @include http://YOUR_SERVER.COM/YOUR_PATH/* // @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js // @require https://gist.github.com/raw/2625891/waitForKeyElements.js // @grant GM_addStyle // ==/UserScript== /*- The @grant directive is needed to work around a design change introduced in GM 1.0. It restores the sandbox. */ waitForKeyElements ( "jQUERY SELECTOR TO THE NODE(S) YOU WANT", changeFontColor ); function changeFontColor (jNode) { jNode.css ("color", "red"); }

Categories : Javascript

Tampermonkey script to edit links in source
Well after fiddling a bit I managed to write a script, here's the code if anyone's interested. // ==UserScript== // @name Google Add // @namespace // @description // @include * // ==/UserScript== var srcs = document.links; var links = document.getElementsByTagName("link"); var scripts = document.getElementsByTagName("script"); var imgs = document.getElementsByTagName("img"); var iframes = document.getElementsByTagName("iframe"); for (i = 0; i < links.length; i++ ) { links[i].href = links[i].href+'?google'; } for (i = 0; i < scripts.length; i++ ) { scripts[i].src = scripts[i].src+'?google'; } for (i = 0; i < imgs.length; i++ ) { imgs[i].src = imgs[i].src+'?google'; } for (i=0; i<srcs.length; i++) { srcs[i].href = srcs[i].hr

Categories : Javascript

alert() doesn't show the value in a Tampermonkey script
Your alert alerts 'extern' because you alert it as a string. alert(extern) will alert the good value. And to make the div visible, just: document.getElementById('div2').style.display = 'block';

Categories : Javascript

Tampermonkey's GM_xmlhttpRequest not implementing 'context' property?
Update: Tampermonkey now reports that this feature is fixed as of version 3.8.4116 (in beta at the moment). See: The bug report The change log Older/generic workaround: The context property is a relatively new feature of GM_xmlhttpRequest(), in Firefox. I doubt it's been implemented in Tampermonkey yet; see Tampermonkey's docs for GM_xmlhttpRequest(). Meanwhile, the tried-and-true method for this kind of thing is to use a closure. Change your GM_xmlhttpRequest() call to something like: ( function (flair_index, flair_text, encoded_name, profile_url, query_url) { GM_xmlhttpRequest ( { method: 'GET', url: xml_url, // Link to a steam profile with ?xml=1 added accept: 'text/xml', onreadystatechange: function (response) { if (response.

Categories : Javascript

Can latest Tampermonkey / Greasemonkey still not use jQuery AJAX?
jQuery AJAX works fine with Tampermonkey and Greasemonkey, with only one limitation compared to jQuery use in a web page. For example, this cross-origin script works in both Tampermonkey and Greasemonkey: // ==UserScript== // @name _Demonstrate jQuery AJAX from Tampermonkey // @include http://stackoverflow.com/questions/18546180/* // @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js // @grant GM_addStyle // ==/UserScript== /*- The @grant directive is needed to work around a design change introduced in GM 1.0. It restores the sandbox. */ $.ajax ( { type: 'GET', url: 'https://api.stackexchange.com/2.1/users/621338?site=stackoverflow&filter=!)2R0ltXnW6.fyPDiHJm', dataType: 'JSON', success: function (apiJson) {

Categories : Jquery

Get the line-number that throws the error in Tampermonkey?
The way I have my configurations, I see everything. Here is how: TamperMonkey Dashboard |> Settings Tab |> General |> Config mode: |> Select Advanced Debug scripts: |> Checked Logging level: |> Select Error (dealer's choice here, I chose this but you can decide)

Categories : Debugging

Hiding content in Chrome settings using Tampermonkey
Update Support for Custom.css has been removed from Chrome in version 32. See this answer. User scripts can't access chrome: scheme. To hide 'Show' button in Chrome password manager, add this CSS code to User StyleSheetsCustom.css file in your profile folder. #password-manager .list-inline-button.custom-appearance { display: none; }

Categories : Javascript

Removing CSS Borders with javascript in greasemonkey/tampermonkey for facebook
border-right is a style property, not an element attribute, so removeAttribute won't work. Instead try this: document.getElementById("mainContainer").style.borderRight = "none"; (Note that border-right becomes borderRight for JavaScript, and make sure you spell names exactly.) However you might prefer user stylesheets. Browser extensions such as Stylish let you write CSS that is applied automatically, instead of going through script. (You can hide things using display: none, or mute them with opacity: 0.5.)

Categories : Javascript

Draw on Java console two squares (one inside of the other)
The simplest way i see is just make a buffer where you will fill the characters you want to draw in console // init buffer char buffer[][] = new char[size][]; for (int i = 0; i < size; i ++) { buffer[i] = new char[size]; } // borders of first square final int sq1Start = 0; final int sq1End = size-1; // draw outer square for(int i = sq1Start; i <= sq1End; i ++){ for (int j = sq1Start; j <= sq1End; j ++) { if (i == sq1Start || i == sq1End || j == sq1Start || j == sq1End) { buffer[i][j] = '*'; } } } // borders of second square final int sq2Start = size / 4; final int sq2End = size * 3 / 4; // draw inner square for (int i = sq2Start; i <= sq2End; i++) {

Categories : Java

How to run Symfony2 console commands inside NetBeans?
Maybe this one will help you, it worked for me... http://software-talk.org/blog/2012/06/symfony2-tutorial-netbeans-and-symfony2-setting-everything-up/

Categories : Symfony2

how does the inside of "if (console.clear)" evaluate to true?
All objects are considered truthy, and functions are objects in JavaScript. If the function is not defined, it will return undefined, which is falsy. One more thing: your code will throw an error if console itself doesn't exist (which is the case in IE<=9 without dev tools open). A safer test would be: if (console && console.clear) { console.clear() };

Categories : Javascript

Ninject Singleton Scope Inside Console Application
It depends if your console app is multi-threaded. If so, you should use InThreadScope so the IDisposable objects will be disposed at the end of the thread. If not, you can stay with InSingletonScope it would make no difference that you would use InThreadScope in singlethread app. If you have some extra demand on scoping, you can try custom scope InScope. Or you can try ninject named scope extensions. Similar question here: Configuring Ninject for a console application and leveraging the existing repository for my MVC application

Categories : C#

How do I add console.log() JavaScript logic inside of a Handlebars template?
Create a Handlebars helper in one of the client-loaded JavaScript files in your project: Template.registerHelper("log", function(something) { console.log(something); }); And then call it in your template: {{log someVariable}} You can log the current context with simply {{log this}}. (Note that in Meteor before version 0.8, or in pure Handlebars outside of a Meteor app, replace Template.registerHelper with Handlebars.registerHelper.)

Categories : Javascript

JavaScript (stored inside assets) not working inside WebView in ICS (Ice Cream Sandwich)
Didn't find any proper solution.. So, I ended up following MoshErsan's suggestion as mentioned here: This is what I did: WebView webView = (WebView) findViewById(R.id.webView); webView.setWebViewClient(new WebViewClient(){ @TargetApi(11) @Override public WebResourceResponse shouldInterceptRequest(WebView view, String url) { Log.d("shouldInterceptRequest", url); InputStream stream = inputStreamForAndroidResource(url); if (stream != null) { return new WebResourceResponse("text/javascript", "utf-8", stream); } return super.shouldInterceptRequest(view, url); } private InputStream inputStreamForAndroidResource(String url) { final String ANDROID_ASSET = "file:///android_asset/"; if (url.contains(ANDR

Categories : Javascript

Displaying error messages on the console when running an executable file inside a Perl script
Huh? A seg fault doesn't cause any output. You can check the error yourself, though: die "Can't launch child: $! " if $? == -1; die "Child killed by signal ".($? & 0x7F)." " if $? & 0x7F; die "Child exited with error ".($? >> 8)." " if $? >> 8;

Categories : Perl

View's collection only working in console.log
It looks like you want to loop through each element in the model. Models have an attributes property that allows you to access the data. If you're using a backbone model: _.each(that.collection.attributes, //... If you're using a backbone collection: _.each(that.collection.models, //...

Categories : Backbone Js

heroku console distinct not working
It seems you haven't set up the database tables correctly on Heroku. Did you do something like run heroku run db:migrate? Why don't you investigate? Have you tried heroku pg:psql? See here. Also, you really shouldn't be using SQLite - it's not the same database - and SQL is not standard across databases. You'll run into a really subtle database bug at some point.

Categories : Ruby On Rails

Acrobat's Javascript console is not working
Finally got my question answered over on Adobe's forums. I thought I had tried everything, but it turns out that I had not even tried a simple Shift + Enter. Hard to believe, since I thought I'd tried every possible key combination already, but I cannot deny the facts. Since I only had the small Apple keyboard without the numeric keypad, I suppose this is the only way to get Enter instead of Return from that key. At any rate, the answer is now known!

Categories : Javascript



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.