I’m printing a web page using the code below: I want to execute a few commands after the Print dialog is closed. How can I detect it? Answer
Tag: javascript
Division and Power in Javascript
I have the following code to divide a variable by 100 and power it. The value in ‘b’ becomes 2 when it should be 0.01 ^ 2 = 0.0001. Why is that? Answer ^ is not the exponent operator. It’s the bitwise XOR operator. To apply a power to a number, use Math.pow(): As to why you get 2 as
Modifying a copy of a JavaScript object is causing the original object to change
I am copying objA to objB same problem for Arrays Answer It is clear that you have some misconceptions of what the statement var tempMyObj = myObj; does. In JavaScript objects are passed and assigned by reference (more accurately the value of a reference), so tempMyObj and myObj are both references to the sam…
Disable contextmenu for a specific container and its children
I need to disable contextmenu only inside a specific div #wrapperand its children, and not the whole page. This is what I’m doing: .. but it doesn’t seem to work. Answer You’re approaching this the wrong way: you’re adding the listener to the document, which may be ok, but it’s e…
Is it possible to attach a click event to a document fragment?
What I have tried: This example does not work. The event is not triggered. Is there any way to attach a click event to a document fragment or is it simply not possible? Answer The click event will not work in this case because document fragment is not appended to DOM structure. Here is what documentation says…
AWS S3 JavaScript SDK getSignedUrl returns base path only
I have some very simple code for generating an S3 URL. The URL I get back from the SDK only has the base path for S3. It doesn’t contain anything else. Why is this happening? Node.js v0.12.0, AWS SDK 2.1.15 or 2.1.17, Windows 7 64-bit, Answer The problem wasn’t with code. It turns out that when yo…
Use jQuery UI datepicker with async AJAX requests
I am trying to enable specific days in a jquery-ui datepicker. So far i have set my sql scripts and json files and everything is working fine except the response time, because i’ve set async to false. My jquery code is. Can anyone help me out? I repeat the above code is working fine but with not good re…
Setting OS Specific Keybindings – Cmd on Mac and Ctrl on Everything Else
When configuring Ace (the text editor), you can use OS specific keybindings, like {win: “Ctrl-Esc”, mac: “Cmd-Esc”}. This shows that you can have OS specific keybindings in JavaScript, but how is it done? I would like to create shortcuts that use Cmd on OS X and Ctrl on other systems. …
How to access first element of JSON object array?
I exptect that mandrill_events only contains one object. How do I access its event-property? Answer To answer your titular question, you use [0] to access the first element, but as it stands mandrill_events contains a string not an array, so mandrill_events[0] will just get you the first character, ‘[&#…
Lat/Long equation in Javascript
I am trying to find an equation for finding the lat/long point between two lat/long points in Javascript. It would work something like this. getMiddle(lat1, lng1, lat2, lng2) <= would return [lat3, lat3] halfway distance wise (going around the earth obviously). I found this: Link Date: 10/11/2001 at 11:41:…