Skip to content
Advertisement

Category: Questions

Best way to share constants between Javascript & CSS

I’m creating a website with lots of dynamic stuff laid out in javascript, as well as CSS. What’s bothering me is that half of my dimension constants (positions and sizes of things on the page) are in my javascript, whereas others are in my CSS. Is there a good way to have a “single place” for constants like this? First

Create an array with random values

How can I create an array with 40 elements, with random values from 0 to 39 ? Like I tried using solutions from here: http://freewebdesigntutorials.com/javaScriptTutorials/jsArrayObject/randomizeArrayElements.htm but the array I get is very little randomized. It generates a lot of blocks of successive numbers… Answer Here’s a solution that shuffles a list of unique numbers (no repeats, ever). If you want

Do tags only go in the tag?

Is it possible/good practice to use <link href””> to include stylesheets outside of the <head> tag, or do they only work / should they be only used in <head>? Answer It’s possible to do it. It’s not recommended to do it, because whatever content comes before the <link> will start rendering and then when the stylesheet is loaded will be

Prevent scrolling of parent element when inner element scroll position reaches top/bottom?

I have a little “floating tool box” – a div with position:fixed; overflow:auto. Works just fine. But when scrolling inside that box (with the mouse wheel) and reaching the bottom OR top, the parent element “takes over” the “scroll request” : The document behind the tool box scrolls. – Which is annoying and not what the user “asked for”. I’m

Browser Timeouts

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

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

Advertisement