Do browsers have built in timeouts and if so what are they? I have a page that does an AJAX call on a process that takes at most 5 minutes to run. Someone said browsers timeout after 2 minutes but didn’t know if there was any truth to that. Answer It’s browser dependent. “By default, Internet Explorer has a KeepAliveTimeout
Tag: javascript
How to convert variables into json?
I want to send json data to ajax but how do you convert variables into json or convert an array to json? Answer If you really want to convert the data into JSON, you have to create an object or array and use JSON.stringify (available in newer browser and can be loaded form here): but you cannot just set the
Javascript Hanging UI on IE6/7
Could anyone suggest performance improvements for the function I’ve written (below, javascript with bits of jquery)? Or point out any glaring, basic flaws? Essentially I have a javascript Google map and a set of list based results too, and the function is fired by a checkbox click, which looks at the selection of checkboxes (each identifying a ‘filter’) and whittles
Define a global variable in a JavaScript function
Is it possible to define a global variable in a JavaScript function? I want use the trailimage variable (declared in the makeObj function) in other functions. Answer As the others have said, you can use var at global scope (outside of all functions and modules) to declare a global variable: (Note that that’s only true at global scope. If that
Why doesn’t JavaScript newlines work inside HTML?
I have the following: As you probably all know, n doesn’t work and I have to use <br> instead. It won’t work either if I link to an external .js file. Here are my questions: Why doesn’t n work? Why does <br> even work? Shouldn’t everything that’s inside the script tags be strictly JavaScript instead of a dirty mix between
Format a Number, Exactly Two in Length?
I have an integer that is less then 100 and is printed to an HTML page with JavaScript. How do I format the integer so that it is exactly two digits long? For example: 01 02 03 … 09 10 11 12 … Answer Update This answer was written in 2011. See liubiantao’s answer for the 2021 version. Original
How to keep an Javascript object/array ordered while also maintaining key lookups?
I have some data which I originally stored in a generic Javascript object, with the ID as a key: However, I discovered that browsers do not guarantee a particular object order when looping through them, so in the above “3” would come before “7”. I switched to using an array format like this: Now, I can loop in the correct
In JavaScript, is it possible save an on-click trigger and re-apply it later?
On a dynamic page I wish to disable and later re-enable sections. Visually they are grayed out, but need to prevent users from playing with the section until later. For elements using on-click triggers, would like to: save the current on-click trigger in an attribute remove the current on-click trigger add trigger that no-defaults and no-propagates to re-enable: get rid
Add characters to a string in Javascript
I need to add in a For Loop characters to an empty string. I know that you can use the function concat in Javascript to do concats with strings But it doesn’t work with my example. Any idea of how to do it in another way? My code : Answer
Change CSS of class in Javascript?
I’ve got a class with the display set to none I’d like to in Javascript now set it to inline I’m aware I can do this with an id with getElementById but what’s the cleanest way to do it with a class? Answer You can do that — actually change style rules related to a class — using the styleSheets array (MDN