I was asked to implement the Konami Code in a website I’m currently working on. It should do the following: Change Background Image Play sound Bring some pop-up What’s the easiest way to achieve this using javascript? Answer Place the code below in a file js/konami.js and reference it in the body …
Author: admin@master
Find all classes in a Javascript application that extend a base class
I have code like this I want to look at all of the classes in my application’s universe, and when I find one that descends from Animal, I want to create a new object of that type and add it to the list. This allows me to add functionality without having to update a list of things. So I can
Using google sign in button with react
I’m trying to use the google sign in in a react application. While using the sign in button as is outside the application itself works great, when using it within a custom SignIn component I can’t get it to work as expected. When the user signs in, the button itself should execute a data-onsuccess…
Using execCommand (Javascript) to copy hidden text to clipboard
I’m trying to copy to clipboard without using Flash, I plan to fall back onto Flash with the use of ZeroClipboard if the browser is incompatible with the javascript approach. I have an onClick listener for the button which looks like: and an input field as follows: This currently works as expected but t…
How come this.hasOwnProperty(‘window’) is true in chrome and false in IE11?
I run this code: In chrome it outputs [window] true in IE11 it outputs [window] false Why? Answer IE messes up the hasOwnProperty method completely as it’s painful with host Objects (host objects don’t have the hasOwnProperty method). What we can do however is access the Object.prototype directly to guarantee…
Defining an array as an environment variable in node.js
I have an array that I pull data from. Since I’m using heroku, it may be better to replace it with an environment variable, but I’m not sure how to do that. Is using a JSON string as an environment variable the way to go? Answer In this scenario, it doesn’t sound like an env var is the way t…
Mongoose – What does the exec function do?
I came across a piece of Mongoose code that included a query findOne and then an exec() function. Ive never seen that method in Javascript before? What does it do exactly? Answer Basically when using mongoose, documents can be retrieved using helpers. Every model method that accepts query conditions can be ex…
Programmatically get FontAwesome unicode value by name
Following the steps outlined in this answer, I am setting my cursor to a FontAwesome icon. Now, I would like to set the cursor to any icon, by class name (for example, fa-pencil). To accomplish this, it seems like I would need to be able to programmatically lookup the unicode value of a given icon. I know tha…
How to select only one DIV from multiple divs using javascript
I have below code in my HTML which has multiple DIV’s, I would like to use these DIV’s as options. For this reason, the DIV which is being clicked should be selectable (leaving others non selected – only one should be active) and when I click on Confirm link, the value within the selected DI…
Convert PHP string to javascript string [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 7 years ago. Improve this question For example, I have this php string: “2015-06-26”. I want to assign it to a java…