Skip to content
Advertisement

How to detect the screen resolution with JavaScript?

Is there a way that works for all browsers? Answer original answer Yes. update 2017-11-10 From Tsunamis in the comments: To get the native resolution of i.e. a mobile device you have to multiply with the device pixel ratio: window.screen.width * window.devicePixelRatio and window.screen.height * window.devicePixelRatio. This will also work on desktops, which will have a ratio of 1. And

When loading an html page via ajax, will script tags be loaded?

When you load an html document using AJAX, what does it do with the nodes inside the HEAD tag: (script,link,style,meta,title) ignore them or load and parse them? And in the case of jquery ‘s ajax() function? Answer When you call the jQuery.ajax() method, you can specify the dataType property, which describes what kind of data you are expecting from the

Best way to add DOM elements with jQuery

So I’ve seen three ways to add html/DOM elements to a page. I’m curious what the pros and cons are for each of them. 1 – Traditional JavaScript I believe the straight JS way to do it is by constructing each element, setting attributes, and then appending them. Example: 2 – Appending a string of html via jQuery I’ve noticed

JavaScript inline events syntax

Is there any reason to use one of the following more than the others: And please do not spend your valuable time to tell me to use jQuery or attachEvent/addEventListener. It’s not really the objective of my question. Answer There’s no difference at all between the first two, in this specific situation the semicolon is optional. The third one will

Write a truly inclusive random method for javascript

Javascript’s MATH object has a random method that returns from the set [0,1) 0 inclusive, 1 exclusive. Is there a way to return a truly random method that includes 1. e.g. While this always returns a number from the set [0,1] it is not truly random. Answer To put it bluntly, what you’re trying to do doesn’t make sense. Remember

What is JSONP, and why was it created?

I understand JSON, but not JSONP. Wikipedia’s document on JSON is (was) the top search result for JSONP. It says this: JSONP or “JSON with padding” is a JSON extension wherein a prefix is specified as an input argument of the call itself. Huh? What call? That doesn’t make any sense to me. JSON is a data format. There’s no

Advertisement