How can I detect what version of JavaScript the browser supports (if any)? I want to check for ECMAScript 3 versus ECMAScript 5 versus ECMAScript 6. Note: I want to avoid the deprecated language tag. Answer I suppose it depends on what you want to do with the information, but many people prefer to do feature detection, instead of figuring
Tag: javascript
Warn user before leaving web page with unsaved changes
I have some pages with forms in my application. How can I secure the form in such a way that if someone navigates away or closes the browser tab, they should be prompted to to confirm they really want to leave the form with unsaved data? Answer Short, wrong answer: You can do this by handling the beforeunload event and
Detecting keydown/up events during HTML5 native drag
I’ve an element that can be dragged using native HTML5. It has dragstart, drag, and dragend event listeners assigned to it. In addition, I also have keydown and keyup event listeners assigned to document.body element. When dragging the draggable element, ondrag event will fire as expected. When I press & release any key while not dragging anything, document.body keydown/up events
Append semicolon on pressing enter key in asp.net textbox
How to add a semicolon to the text in asp.net text box (web application), on pressing enter and move the cursor to next line? Answer Here is a solution using pure JavaScript. HTML Code Behind (onclick javascript event wire up) JavaScript
Download a file from NodeJS Server using Express
How can I download a file that is in my server to my machine accessing a page in a nodeJS server? I’m using the ExpressJS and I’ve been trying this: But I can’t get the file name and the file type ( or extension ). Can anyone help me with that? Answer Update Express has a helper for this to
Javascript .replace command replace page text?
Can the JavaScript command .replace replace text in any webpage? I want to create a Chrome extension that replaces specific words in any webpage to say something else (example cake instead of pie). Answer The .replace method is a string operation, so it’s not immediately simple to run the operation on HTML documents, which are composed of DOM Node objects.
Page reload in Chrome unnecessarily triggers bound events just prior to reloading the page
Hope someone has a good answer to this: Why does Chrome (14.0) triggers the document ready and window load events when I refresh the page? Note that I am not talking about what happens when the new page loads, but before it has loaded. See the following code: When I first visit page I get two outputs on console, one
Replace too long strings with “…”
Lets say we have a <div style=”width:100px;”>This text is too long to fit</div> The text in the div is dynamic. And I’d like to force the text to fit in width and not break. So i need some kind of functionality to test if the text is going to fit, and if it is not, then i’d like to display
How to create dictionary and add key value pairs dynamically in Javascript
From post: Sending a JSON array to be received as a Dictionary<string,string> I’m trying to do this same thing as that post, the only issue is that I don’t know what the keys and the values are upfront. So I need to be able to dynamically add the key and value pairs and I don’t know how to do that.
Wait until a condition is true?
I’m using navigator.geolocation.watchPosition in JavaScript, and I want a way to deal with the possibility that the user might submit a form relying on location before watchPosition has found its location. Ideally the user would see a ‘Waiting for location’ message periodically until the location was obtained, then the form would submit. However, I’m not sure how to implement this