How to detect responsive breakpoints of Twitter Bootstrap 3 using JavaScript?

Edit: This library is now available through Bower and NPM. See github repo for details. UPDATED ANSWER: Live example: CodePen Latest version: Github repository Don’t like Bootstrap? Check: Foundation demo and Custom framework demos Have a problem? Open an issue Disclaimer: I’m the author. Here’s a few things you can do using the latest version … Read more

Event when window.location.href changes

I use this script in my extension “Grab Any Media” and work fine ( like youtube case ) var oldHref = document.location.href; window.onload = function() { var bodyList = document.querySelector(“body”) var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (oldHref != document.location.href) { oldHref = document.location.href; /* Changed ! your code here */ } }); … Read more

Is it possible to append to innerHTML without destroying descendants’ event listeners?

Using .insertAdjacentHTML() preserves event listeners, and is supported by all major browsers. It’s a simple one-line replacement for .innerHTML. var html_to_insert = “<p>New paragraph</p>”; // with .innerHTML, destroys event listeners document.getElementById(‘mydiv’).innerHTML += html_to_insert; // with .insertAdjacentHTML, preserves event listeners document.getElementById(‘mydiv’).insertAdjacentHTML(‘beforeend’, html_to_insert); The ‘beforeend’ argument specifies where in the element to insert the HTML content. Options … Read more

In React, what’s the difference between onChange and onInput?

It seems there is no real difference React, for some reason, attaches listeners for Component.onChange to the DOM element.oninput event. See the note in the docs on forms: React docs – Forms There are more people that are surprised by this behavior. For more details, refer to this issue on the React issue tracker: Document … Read more

How to simulate a mouse click using JavaScript?

(Modified version to make it work without prototype.js) function simulate(element, eventName) { var options = extend(defaultOptions, arguments[2] || {}); var oEvent, eventType = null; for (var name in eventMatchers) { if (eventMatchers[name].test(eventName)) { eventType = name; break; } } if (!eventType) throw new SyntaxError(‘Only HTMLEvents and MouseEvents interfaces are supported’); if (document.createEvent) { oEvent = … Read more

Detect Click into Iframe using JavaScript

This is certainly possible. This works in Chrome, Firefox, and IE 11 (and probably others). const message = document.getElementById(“message”); // main document must be focused in order for window blur to fire when the iframe is interacted with. // There’s still an issue that if user interacts outside of the page and then click iframe … Read more

Using Chrome, how to find to which events are bound to an element

Using Chrome 15.0.865.0 dev. There’s an “Event Listeners” section on the Elements panel: And an “Event Listeners Breakpoints” on the Scripts panel. Use a Mouse -> click breakpoint and then “step into next function call” while keeping an eye on the call stack to see what userland function handles the event. Ideally, you’d replace the … Read more

Is there any way to call a function periodically in JavaScript?

The setInterval() method, repeatedly calls a function or executes a code snippet, with a fixed time delay between each call. It returns an interval ID which uniquely identifies the interval, so you can remove it later by calling clearInterval(). var intervalId = setInterval(function() { alert(“Interval reached every 5s”) }, 5000); // You can clear a … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)