Some websites have code to “break out” of IFRAME enclosures, meaning that if a page A is loaded as an IFRAME inside an parent page P some Javascript in A redirects the outer window to A. Typically this Javascript looks something like this: My question is: As the author of the parent page P and not being the author of
Tag: javascript
Determine when an user is typing
I am building a search box (input field) which should make a server call to filter a grid with the text being inserted on it but I need to make this in an smart way, I need to fire the server call only if the user has stopped. Right now I’m trying to implement it, but if someone knows how
Detect which form input has focus using JavaScript or jQuery
How do you detect which form input has focus using JavaScript or jQuery? From within a function I want to be able to determine which form input has focus. I’d like to be able to do this in straight JavaScript and/or jQuery. Answer I am not sure if this is the most efficient way, but you could try:
How to append something to an array?
This question’s answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions. How do I append an object (such as a string or number) to an array in JavaScript? Answer Use the Array.prototype.push method to append values to the end of an array: You can use the push() function
Avoiding a Javascript race condition
My users are presented a basically a stripped down version of a spreadsheet. There are textboxes in each row in the grid. When they change a value in a textbox, I’m performing validation on their input, updating the collection that’s driving the grid, and redrawing the subtotals on the page. This is all handled by the OnChange event of each
Get the name of an object’s type
Is there a JavaScript equivalent of Java’s class.getName()? Answer Is there a JavaScript equivalent of Java’s class.getName()? No. ES2015 Update: the name of class Foo {} is Foo.name. The name of thing’s class, regardless of thing’s type, is thing.constructor.name. Builtin constructors in an ES2015 environment have the correct name property; for instance (2).constructor.name is “Number”. But here are various hacks
What is the best way to determine the number of days in a month with JavaScript?
I’ve been using this function but I’d like to know what’s the most efficient and accurate way to get it. Answer Day 0 is the last day in the previous month. Because the month constructor is 0-based, this works nicely. A bit of a hack, but that’s basically what you’re doing by subtracting 32. See more : Number of days
caching JavaScript files
Which is the best method to make the browser use cached versions of js files (from the serverside)? Answer Have a look at Yahoo! tips: https://developer.yahoo.com/performance/rules.html#expires. There are also tips by Google: https://developers.google.com/speed/docs/insights/LeverageBrowserCaching
What is JavaScript’s highest integer value that a number can go to without losing precision?
Is this defined by the language? Is there a defined maximum? Is it different in different browsers? Answer JavaScript has two number types: Number and BigInt. The most frequently-used number type, Number, is a 64-bit floating point IEEE 754 number. The largest exact integral value of this type is Number.MAX_SAFE_INTEGER, which is: 253-1, or +/- 9,007,199,254,740,991, or nine quadrillion seven
Django Template Variables and Javascript
When I render a page using the Django template renderer, I can pass in a dictionary variable containing various values to manipulate them in the page using {{ myVar }}. Is there a way to access the same variable in Javascript (perhaps using the DOM, I don’t know how Django makes the variables accessible)? I want to be able to