Skip to content
Advertisement

What is the difference between decodeURIComponent and decodeURI?

What is the difference between the JavaScript functions decodeURIComponent and decodeURI? Answer To explain the difference between these two let me explain the difference between encodeURI and encodeURIComponent. The main difference is that: The encodeURI function is intended for use on the full URI. The encodeURIComponent function is intended to be used on .. well .. URI components that is

Parse and add url from clipboard

I need a javascript bookmark to take the url I have in the clipboard parse out the 2 numbers and create a new url, and add a link to the top of the page, that when clicked adds the url to my bookmark menu. Say I have url’s like these http://www.website.com/frontpageeditor.jhtml?sectionID=2844&poolID=6276 javascript:getPoolPageUrl(9800,22713) Then I need to add the numbers to

Generating PDF files with JavaScript

I’m trying to convert XML data into PDF files from a web page and I was hoping I could do this entirely within JavaScript. I need to be able to draw text, images and simple shapes. I would love to be able to do this entirely in the browser. Answer I’ve just written a library called jsPDF which generates PDFs

How do I correctly clone a JavaScript object?

I have an object x. I’d like to copy it as object y, such that changes to y do not modify x. I realized that copying objects derived from built-in JavaScript objects will result in extra, unwanted properties. This isn’t a problem, since I’m copying one of my own literal-constructed objects. How do I correctly clone a JavaScript object? Answer

Alternative for innerHTML?

EDIT: WOW. This question is 12 years old now. As someone stated, it can be done with a one-liner since 2016: https://stackoverflow.com/a/69322509/80907 The original: I’m wondering if there’s a way to change the text of anything in HTML without using innerHTML. Reason I’m asking is because it’s kinda frowned upon by the W3C. I know it’s nitpicking, but I just

How do you add CSS with Javascript?

How do you add CSS rules (eg strong { color: red }) by use of Javascript? Answer You can also do this using DOM Level 2 CSS interfaces (MDN): …on all but (naturally) IE8 and prior, which uses its own marginally-different wording: There is a theoretical advantage in this compared to the createElement-set-innerHTML method, in that you don’t have to

Disable Drag and Drop on HTML elements?

I’m working on a web application for which I’m attempting to implement a full featured windowing system. Right now it’s going very well, I’m only running into one minor issue. Sometimes when I go to drag a part of my application (most often the corner div of my window, which is supposed to trigger a resize operation) the web browser

How to quickly clear a JavaScript Object?

With a JavaScript Array, I can reset it to an empty state with a single assignment: This makes the Array “appear” empty and ready to reuse, and as far as I understand is a single “operation” – that is, constant time. Is there a similar way to clear a JS Object? I know I can iterate its fields deleting them:

Advertisement