Skip to content

Author: admin@master

How to add listener for a custom event in the DOM?

What I want is to create my own function that will be bound as an event listener similar to how other event listeners (e.g., onclick) are set: Is it possible and if so how? Answer The problem you have is the browser does not realize it is a function in there. It is a string, the only way you can

How to define setter/getter on prototype

EDIT Oct 2016: Please note this question was asked in 2012. Every month or so someone adds a new answer or comment that refutes an answer, but doesn’t really make sense to do so as the question is probably out of date (remember, it was for Gnome Javascript to write gnome-shell extensions, not browser st…

how to get youtube video id from url

I am trying to check whether a url is a valid youtube video URL and get the youtube video ID from it, so far I am using a simple javascript split function in order to achieve this, however this has some minor disadvantages as youtube has multiple URL’s. I have been viewing other stackoverflow threads ho…

Sending websocket ping/pong frame from browser

I keep reading about ping/pong messages in websockets to keep the connection alive, but I’m not sure what they are. Is it a distinct frame type? (I don’t see any methods on a javascript WebSocket object in chrome related to ping-pong). Or is it just a design pattern (e.g. I literally send “p…

setInterval(function(),time) change time on runtime

I want to change setInterval function time when my code is running. I try this First SetInterval does not work! Answer You’re clearing the interval on the next line, so the first one wont work, as it gets cleared right away : Also, as gdoron says, setting a interval of nothing isn’t really valid, …