Click button copy to clipboard

Edit as of 2016 As of 2016, you can now copy text to the clipboard in most browsers because most browsers have the ability to programmatically copy a selection of text to the clipboard using document.execCommand(“copy”) that works off a selection. As with some other actions in a browser (like opening a new window), the copy to … Read more

Uncaught TypeError: data.push is not a function

To use the push function of an Array your var needs to be an Array. Change data{“name”:”ananta”,”age”:”15″} to following: The containing Array Items will be typeof Object and you can do following: var text = “You are ” + data[0]->age + ” old and come from ” + data[0]->country; Notice: Try to be consistent. In my example, … Read more

Access Control Request Headers, is added to header in AJAX request with jQuery

What you saw in Firefox was not the actual request; note that the HTTP method is OPTIONS, not POST. It was actually the ‘pre-flight’ request that the browser makes to determine whether a cross-domain AJAX request should be allowed: http://www.w3.org/TR/cors/ The Access-Control-Request-Headers header in the pre-flight request includes the list of headers in the actual … Read more

Proper way to wait for one function to finish before continuing?

One way to deal with asynchronous work like this is to use a callback function, eg: As per @Janaka Pushpakumara’s suggestion, you can now use arrow functions to achieve the same thing. For example: firstFunction(() => console.log(‘huzzah, I\’m done!’)) Update: I answered this quite some time ago, and really want to update it. While callbacks are … Read more

When is JavaScript synchronous?

JavaScript is always synchronous and single-threaded. If you’re executing a JavaScript block of code on a page then no other JavaScript on that page will currently be executed. JavaScript is only asynchronous in the sense that it can make, for example, Ajax calls. The Ajax call will stop executing and other code will be able to … Read more