w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Greasemonkey script seems to execute lines out of order
Try this .. setTimeout(function(){$("#cat_1").attr("checked",true);},0); If it is a race condition of some kind this will put your command at the bottom of the stack.

Categories : Javascript

Toggle JavaScript OnClick function seconds after seconds
What you need is setTimeout() Calls a function or executes a code snippet after specified delay. Your list_activity function should like function list_activity ( setTimeout(function () { formid.submit(); }, 2000); } }

Categories : Javascript

Call a Javascript function every x seconds and stop after y seconds?
Given this: I want to call a Javascript function after clicking a button, make it loop every 100 milliseconds for 1,5 seconds and then pause it. This should do it: http://jsfiddle.net/pUWHm/ // I want to call a Javascript function after clicking a button $('.button').click(function() { var started = Date.now(); // make it loop every 100 milliseconds var interval = setInterval(function(){ // for 1.5 seconds if (Date.now() - started > 1500) { // and then pause it clearInterval(interval); } else { // the thing to do every 100ms $(".ac-big").customScrollbar("resize") } }, 100); // every 100 milliseconds }); The strategy is to start the interval when you click the button, and you save that interval id. You also save when you sta

Categories : Javascript

If function execute more than x seconds php
The function get_headers() doesn't supports a timeout or a context param. Try: ini_set('default_socket_timeout', YOUR_VALUE_IN_SECONDS); This will set the default timeout to a value of your choice. Don't forget to reset the timeout after the operation has finished.

Categories : PHP

execute a PHP method every X seconds?
It looks to me like the websocket-framework you are using is too primitive to allow your server to do other useful things while waiting for connections from clients. The only call to PHP's socket_select() function is hard-coded to a one second timeout, and it does nothing when the time runs out. It really ought to allow a callback or an outside loop. Look at the http://php.net/manual/en/function.socket-select.php manual page. The last parameter is a timeout time. socket_select() waits for incoming data on a socket or until the timeout time is up, which sounds like what you want to do, but the library has no provision for it. Then look at how the library uses it in core/classes/SocketServer.php. I'm assuming you call run() and then it just never returns to your calling code until it

Categories : PHP

replacing text between two strings in javascript using greasemonkey
The easiest way to do this would be with a regular expression. var comment = "[youtube]http://www.youtube.com/embed/XGSy3_Czz8k[/youtube]", match = comment.match(/[youtube]([^[]*)[/youtube]/); if (match) { var iframe = document.createElement("iframe"); iframe.src = match[1]; document.body.appendChild(iframe); }

Categories : Javascript

How can I submit this form properly with javascript/greasemonkey?
With jQuery you could submit this form like this: In this function you can process the data of the form. $(document).on("submit", "form", function(e){ e.preventDefault(); // get the data of the form var url = $(this).attr("action"), _csrf_token = $(this).find("input name=['_csrf_token']).val(); // jquery ajax call for example $.ajax( ); });

Categories : Javascript

Execute any X file in a directory every X seconds
metacode: forever read content of directory (depending on your operating system, f.e. DosFindFirst) for each content which is a .bat (and not empty) call system sleep (inside or out side the for each depending on your needs)

Categories : C

How to execute a PHP file in background for every 30 seconds
You are looking for CRON, this helps you to schedule your task at your scheduled time. That is your could execute/run your PHP script at the time scheduled by you. * * * * * /path/to/php_file * * * * * sleep 15; /path/to/php_file * * * * * sleep 30; /path/to/php_file * * * * * sleep 45; /path/to/php_file The above cron job will run your php script for every 15 seconds. Here sleep will help to delay the script for every 15 seconds.

Categories : PHP

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

Adding javascript to a XML file transformed with XSLT using a Greasemonkey script
Don't use onclick. This goes triple for userscripts, as there are additional scope and/or sandbox conflicts. Also, it's a poor idea to try and add JS into the XSLT file/text, and there is no need for script injection in this case either. Use the script to do whatever JS manipulation you have in mind. For example: // ==UserScript== // @name _XML Renderer with javascript functionality // @description Stylesheet and javascript for xml results // @include http://YOUR_SERVER.COM/YOUR_PATH/*.xml // @resource xslFile Q_17998446_transform.xsl // @grant GM_getResourceText // ==/UserScript== var xsl_str = GM_getResourceText ("xslFile"); var processor = new XSLTProcessor (); var dataXSL = new DOMParser ().parseFromString (xsl_str, "text/xml"); processor.importSty

Categories : Javascript

Wait for few seconds to let download finish and then execute PHP code
Why not just use PHP to download the image? download image file from given google chart api url using php header('Content-Type: image/png'); header('Content-Disposition: attachment; filename="chart.png"'); $image = file_get_contents('http://chart.apis.google.com/chart? chs=300x300&cht=qr&chld=L|0&chl=http%253A%252F%252Fnetcane.com%252Fprojects%252Fyourl%252F3'); header('Content-Length: ' . strlen($image)); echo $image;

Categories : PHP

Merging n Dictionary instances & execute action on duplicate keys
var result = myDictionaries.SelectMany(x=>x) .GroupBy(d=>d.Key) .Select(g=> new KeyValuePair<string,int>(g.Key, g.Sum(x=>x.Value))) .ToDictionary(k=>k.Key,v=>v.Value);

Categories : C#

PHP + JavaScript countdown echo 5 seconds / 1 second
set the "s" as a variable. if counter == 1, set that variable to an empty string, and then update your div accordingly: function() { var plural = "s"; if (counter == 1) { plural = ""; } // update div }

Categories : PHP

Page Redirect after X seconds wait using JavaScript
You actually need to pass a function inside the window.setTimeout() which you want to execute after 5000 milliseconds, like this: $(document).ready(function () { // Handler for .ready() called. window.setTimeout(function () { location.href = "https://www.google.co.in"; }, 5000); }); For More info: .setTimeout()

Categories : Javascript

convert seconds to {H hr MM min} time format with javascript
hours is (total_seconds / 60) / 60 minutes is (total_seconds / 60) % 60 seconds is (total_seconds % 60) % 60 where / is integer division (division that discards the remainder) and % is the modulo function.

Categories : Javascript

stop execution after 10 seconds javascript / jquery
Your counter stops because you only run the code to update it once every 10 seconds. You are using setInterval with a 10000 millisecond delay, so the timer function is called every 10 seconds, I think you should use a 1 second interval instead. The following code will run every second, so the "timer" div will be updated with the number of seconds left, then when count becomes less then timeout, the game over code will run. var counter = setInterval(timer, 1000); // Make sure "count" and "timeout" are sane values. What are they defined to initially? function timer() { count = count - 1; if (count < timeout) { clearInterval(counter); imageUrl = "img/BGgameover.gif"; $('#stage').css('background-image', 'url(' + imageUrl + ')'); $('#bomb').remove(); $('

Categories : Javascript

Changing Javascript Counter From Seconds To Milliseconds
In this line: this.currentTime.setSeconds(this.currentTime.getSeconds() + 1); the code update its currentTime, setting it one second forward. The function is executed every second, so this effectly works like it's getting the current time. If you change it to run ever .5 seconds, it would advance the seconds twice as fast as it should, causing it to regress when you refresh the page. If you let it run for 3 seconds, it would add 6 seconds instead, so if you reload it then the clock would seem to go back 3 seconds when getting the current time. For some reason, the code doesn't get the current date by calling new Date() instead (Performance? Memory management?), so you'll have to change how it moves the currentTime forward to fix the bug, making increments in milliseconds instead of s

Categories : Javascript

Javascript, counting in seconds - adding a point each time
docuement is spelt "document", .innerHTML is not a function call (set it like a variable) & variables and functions share the same namespace, i.e. don't set a variable points_per_second and then declare a function of the same name. Once you have your syntax errors sorted, you were probably looking for setInterval. var total_points = 0; var points_per_click = 1; var points_per_second = 2; function update_display(){ var el = document.getElementById("current_points"); el.innerHTML = "Current Points: " + total_points; //insert here? ... No } var ticker = setInterval(function(){ total_points += points_per_second; // ... or whatever your intended logic update_display(); }, 1000); jsFiddle

Categories : Javascript

Format Javascript Date into Hours Minute Seconds
setInterval(function() { var local = new Date(); var localdatetime = local.getHours() + ":" + local.getMinutes() + ":" + local.getSeconds(); var remote = new Date(); remote.setHours(local.getHours() - 5); var remotedatetime = remote.getHours() + ":" + remote.getMinutes() + ":" + remote.getSeconds(); $('#local-time').html(localdatetime); $('#remote-time').html(remotedatetime); },1000);

Categories : Javascript

How to stop timer after ten seconds in javascript using setInterval and clearInterval?
Because you named a local variable named tt which does not let you access the global variable tt. Very bad planning on variable names. Your code also will not stop at 10 seconds, it will stop when the time is at 10 seconds or 10 minutes. function checkTime(xtt) { if (xtt==10) { xtt="0" + xtt; console.log(xtt); clearInterval(tt); } return xtt; }

Categories : Javascript

Using Javascript to rate limit and queue ajax calls to once every 15 seconds
Have a go with this <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Queue things</title> <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script> <script type="text/javascript"> var myQueue=[],msgNum=0; function queueIt(item) { myQueue.push({ "item":item, "ts":new Date().getTime()}); } function processQueue() { if (myQueue.length===0) return; var obj = myQueue.shift(); $("#content").append('<br/>'+obj.item+" "+diff(obj.ts)); } function diff(ts) { var t = new Date().getTime()-ts; return t + "ms ago"; } $(function(){ $("#clickMe").on("click",function() { msgNum++; queueIt("Message #"+msgNum); }); setInterval(processQueue,15000); }); </sc

Categories : Javascript

Count how many seconds did the user hover an element using jquery or javascript?
You've tagged the question with JQuery, so here's a jQuery solution. $(element).on('mouseover', function(e){ $(e.target).data('hover-start', new Date().getTime()); }); $(element).on('mouseout', function(e){ // count the difference var difference = new Date().getTime() - $(e.target).data('hover-start'); // clean up the data $(e.target).data('hover-start', undefined); console.log('Mouse was over for', difference/1000, 'seconds'); });

Categories : Javascript

Trouble getting div layer and javascript to delay a few seconds after page load
This line $(function () { is a short for the more expressive jQuery(document).ready function, handling cross-browser comfortable the DOMContentLoaded event: jQuery(document).ready(function () { // this is the place (to delay something) // after page parsed / document ready: setTimeout(show, 5000); }); Another loading event is (also known as window.onload) jQuery(window).load(function () { // this is the place // after page and html images are loaded }); I see you also try to select elements by a typical class identifier .bannergroup, for which you would have to use getElementsByClassName('bannergroup') (without the dot). However because you have jQuery, let's do it easy: function show() { $('.bannergroup').css({ display: 'inline' }); // now .rotate(

Categories : Javascript

Where clause is slowing my query from 2 seconds to 24 seconds
You might need an index on the table. Typically you will need an index on any columns used in the where clause as for the (+) syntax I think it is redundant (i'm no Oracle expert) but see Difference between Oracle's plus (+) notation and ansi JOIN notation?

Categories : SQL

Javascript duplicate ids
Every time you click the button, you add another keydown binding to #textarea. So if you click the button 5 times, then when you press Enter the keydown binding will be run 5 times. You should move $('#postDiv').on('keydown', '#textarea', ...) outside the function, and just do it once in the document ready handler.

Categories : PHP

Duplicate Javascript countdown
First you need to put this html in the same location as the other counter: <div id="countdown2"> <div class="event-title"> </div> <div id="countbox2"></div> <div class="event-title"></div> </div> add this to styles.css: #countdown2 { position: absolute; left: 688px; top: 290px; width: 244px; height: 86px; line-height: 150%; color: #e0d1aa; } #countdown2 .event-title { position: absolute; left: 6px; top: 75px; width: 227px; text-align: center; font-family: 'Fjalla One', sans-serif; font-size: 13px; line-height: 125%; text-transform: uppercase; color: #000; } #countdown2 .days, #countdown2 .hours, #countdown2 .minutes, #countdown2 .seconds, #countdown2 .hund

Categories : Javascript

How to check for duplicate row using javascript
Using this code it will check for duplication in one table column then take all rows of table that are duplicated and put their ids in array so you will get an array of rows id but ur table has to have an id for each row var columnNumber = 1; var table = document.getElementById('t1'); var rowLength = table.rows.length; var arrReocrds = new Array(); var arrCount = 0; var listCount = 0; var arr = new Array(); $('#t1 td:nth-child(' + colNumber + ')').each(function () { var recordValue = $(this).html().trim(); var flagFirstTime = true; //loop through table to check redundant of current record value for (var i = 1; i < rowLength; i += 1) { { var row = table.rows[i]; var recordId = //put

Categories : Javascript

check duplicate data with javascript
You should have your ASP.NET button implement both the OnClick event (to execute server-side code once it is determined that there is not duplicate data) and OnClientClick event (to execute your JavaScript that will call to check if there is duplicate data). I suggest the following: In JavaScript, add a jQuery click event to your button, like this: $( "#myButton" ).click(function() { }); Note: I have assumed the name of your button to be myButton, change it to match the ID of your button in markup. Now you will need to call server-side to execute your logic to look for duplicate data. I recommend using ASP.NET AJAX Page Methods invoked via the jQuery .ajax() function, like this: $.ajax({ type: "POST", url: "YourPage.aspx/DoesDataExist", data: "{'codeValue': $('#myTextBo

Categories : Javascript

I want my body background image to fade in and fade out every 5 seconds, if not atleast change every 5 seconds
The path is wrong. $('body').css('background-image','url(/background' + curImgId + '.jpg)'); Your images are in ../images/backgrouds/ and the first attempt tries the URL http://mrinalikamath.in/background0.jpg . However, you want http://mrinalikamath.in/images/backgrounds/bg0.jpg : $('body').css('background-image','url(/images/backgrounds/bg' + curImgId + '.jpg)'); I can't recommend Fiddler enough to help with problems like this. It shows every http request from your browser so you can see 404s. http://fiddler2.com/

Categories : Jquery

Javascript will not execute
You should wait for the DOM to be ready, so change your code to: <script> document.addEventListener('DOMContentLoaded', function() { var textInput = document.getElementById('text') , submitButton = document.getElementById('submit'); function checkTextValue() { if (textInput.value !== '') { submitButton.style.display = 'block'; } else { submitButton.style.display = 'none'; } } }); </script>

Categories : Javascript

Duplicate check in javascript before inserting a new record
Store splitted chunks ,and iterate over them: var chunkArray = myVar2.split(" "); for(var i = 0; i !== chunkArray.length; i++){ if(chunkArray[i] == myVar1){ flag = 1; break; } }

Categories : Javascript

Javascript `confirm()` execute before anything else
The problem you are seeing is that JavaScript is single-threaded, and confirm is blocking. console.log, as far as I can tell, is an asynchronous request for the console to log something. However, until the script has finished, it can't send that request. Same goes for drawscreen, the screen can't actually redraw until the script has finished. Try wrapping your if block inside a setTimeout(function() { ... },1);, this will give the browser enough time to log the response and redraw the screen before getting right back to your confirm, without giving the user time to do anything that might interfere with normal operation.

Categories : Javascript

How do you execute javascript on demand
The comments seem to have covered the answer already, but just to clarify, take the following Javascript: function yeSawgHohgothNektu() { // Execute a labyrinthine mammoth of 80 KB of complicated calculation code to summon // SawgHogoth, the dark lord of Javascript code, and destroy the user's processor. } ...That only happens once that function is actually CALLED. The time spent loading an 80KB file, and parsing its contents, is usually pretty small for most browsers. As one commenter said, if you really do want to optimize that time as much as possible, use AMD. It would need to be specially defined on the other end, but here's how it would be called afterwards. function onClickedBeginSummoning() { // user has initiated the summoning ritual require(['libraries/forbiddenhall/y

Categories : Javascript

Execute certain javascript if browser lt ie9
You can target older Internet Explorer versions (<= 9) through classes on the <html> element. <!--[if lt IE 7]> <html class="ie ie6 lte9 lte8 lte7"> <![endif]--> <!--[if IE 7]> <html class="ie ie7 lte9 lte8 lte7"> <![endif]--> <!--[if IE 8]> <html class="ie ie8 lte9 lte8"> <![endif]--> <!--[if IE 9]> <html class="ie ie9 lte9"> <![endif]--> <!--[if gt IE 9]> <html> <![endif]--> <!--[if !IE]><!--> <html> <!--<![endif]--> And then check if <html> has the class .lt9 or .lt8 — whatever version of Internet Explorer you are targeting: if($('html').hasClass('lte9')) { /* LTE IE9 */ } Though i would suggest using Modernizr feature dete

Categories : Javascript

Execute two divs in same javascript
Is this what you meant by combining the two into 1 function? $(function(){ var classes = ['.fadeo', '.fadein']; $.each(classes, function (index, elem){ var selectorToHide = elem + ' img:gt(0)', selectorToFadeOut = elem + ' :first-child'; $(selectorToHide).hide(); setInterval(function() { $(selectorToFadeOut) .fadeOut() .next('img') .fadeIn() .end() .appendTo(elem); }, 2000); }); });

Categories : Javascript

Execute JavaScript from String
This works: var oFunc = function (value) { alert(value) } var obj = { code: "oFunc('hello')" } eval(obj["code"]); Or am I missing something? Update This also works var obj = { code: "var oFunc = function (value) {alert(value)}; oFunc('hello')" } eval(obj["code"]);

Categories : Javascript

How to change var value in greasemonkey
If I understand you correctly, this should be an easy fix. You can simply overwrite the variable: So replace myInfo { "plusActive":true; } with plusActive = true; You shouldn't need to run any sort of a function, assuming the variable in question is not read until the page is loaded (which is far from certain).

Categories : Misc

How would I remove a DIV if there are no IDs using Greasemonkey?
We might need to see the whole page to work out robust selectors for those <div>s. But, if they always contain iframes with src attributes to undesirable content, then you can use those iframes to hunt down the dastardly divs. Make a list of key text snippets in the bad iframe src attributes. I'm also using jQuery and waitForKeyElements(), in case this content is added by AJAX. So, the script looks something like this: // ==UserScript== // @name _Remove bad divs containing bad iframes // @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 de

Categories : Javascript

Using json_encode() to pass into JavaScript from PHP PDO causes a duplicate in the foreach in this code
You are getting the results in both numerically indexed and associative format because that's the default PDO fetch mode. This can be changed with PDOStatement::setFetchMode. For example, setting the fetch mode to PDO::FETCH_ASSOC will remove the 0 keys from your result arrays and leave just id: $data->setFetchMode(PDO::FETCH_ASSOC); foreach($data as $row) { $r[] = json_encode($row); }

Categories : PHP



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