Skip to content
Advertisement

Tag: javascript

Convert SVG to image (JPEG, PNG, etc.) in the browser

I want to convert SVG into bitmap images (like JPEG, PNG, etc.) through JavaScript. Answer Here is how you can do it through JavaScript: Use the canvg JavaScript library to render the SVG image using Canvas: https://github.com/gabelerner/canvg Capture a data URI encoded as a JPG (or PNG) from the Canvas, according to these instructions: Capture HTML Canvas as gif/jpg/png/pdf?

Get contentEditable caret position

I’m finding tons of good, cross-browser answers on how to set the caret position in a contentEditable element, but none on how to get the caret position in the first place. What I want to do is know the caret position within a div on keyup. So, when the user is typing text, I can, at any point, know the

Javascript to remove spaces from a textbox value

I’ve searched around for this a lot and can’t find a specific example of what I’m trying to do. Basically I want to get the value of a textbox, by the name of the text box (not id). Then I want to remove ALL spaces, not just leading or trailing, but spaces in the text too. For example for this

Remove all child elements of a DOM node in JavaScript

How would I go about removing all of the child elements of a DOM node in JavaScript? Say I have the following (ugly) HTML: And I grab the node I want like so: How could I remove the children of foo so that just <p id=”foo”></p> is left? Could I just do: or should I be using some combination of

JavaScript file not updating no matter what I do

I have an external JavaScript file and whether in FireFox or Chrome, whether all browsing data is cleared, it will NOT update no matter what. I believe something happened when I made a backup of my file, which I simply added “_thedate” to the end of the name. Then Save As back to the original name. Now I cannot seem

How do I shuffle the characters in a string in JavaScript?

In particular, I want to make sure to avoid the mistake made in Microsoft’s Browser Choice shuffle code. That is, I want to make sure that each letter has an equal probability of ending up in each possible position. e.g. Given “ABCDEFG”, return something like “GEFBDCA”. Answer I modified an example from the Fisher-Yates Shuffle entry on Wikipedia to shuffle

Can setTimeout ever return 0 as the id?

I am writing a check to see if a timeout is active. I was thinking of doing this: I was wondering if it would ever be possible that a will be 0. In that case I would use a !== null Answer First: 0 isn’t the same as null, (0 == null) would be false in every case’; if you

Load google maps v3 dynamically with ajax

When i try to load google maps v3 with ajax the result is: in the source code, i suppose that writes with javascript document.write(); how i can do this without iframe? thanks. Answer This is not supported. Please load the API using supported methods: http://code.google.com/apis/maps/documentation/javascript/tutorial.html#Loading_the_Maps_API

Download data URL file

I’m playing with the idea of making a completely JavaScript-based zip/unzip utility that anyone can access from a browser. They can just drag their zip directly into the browser and it’ll let them download all the files within. They can also create new zip files by dragging individual files in. I know it’d be better to do it serverside, but

Checking if a URL is broken in Javascript

This question has been posted on Stack before, but none so specific as to what I’m trying to understand. The simplest way to check if a URL is corrrect to send a http Head request. But how do you use that to specify the URL ? I found this in a previous post : But it doesn’t seem to run

Advertisement