What is the difference between document.location.href and document.location?

document.location is a synonym for window.location that has been deprecated for almost as long as JavaScript has existed. Don’t use it. location is a structured object, with properties corresponding to the parts of the URL. location.href is the whole URL in a single string. Assigning a string to either is defined to cause the same kind of navigation, so take your … Read more

JavaScript Loading Screen while page loads

You can wait until the body is ready:  Run code snippetExpand snippet Here is a JSFiddle that demonstrates this technique. Update Here is a modern version using promises. The promise is completely optional now, as it is only used for a delay. The DOMContentLoaded event will fire once the page is loaded.

HTML5 Local storage vs. Session storage

localStorage and sessionStorage both extend Storage. There is no difference between them except for the intended “non-persistence” of sessionStorage. That is, the data stored in localStorage persists until explicitly deleted. Changes made are saved and available for all current and future visits to the site. For sessionStorage, changes are only available per tab. Changes made are saved and available for the current page in that tab until … Read more

Use images like checkboxes

Pure semantic HTML/CSS solution This is easy to implement on your own, no pre-made solution necessary. Also it will teach you a lot as you don’t seem too easy with CSS. This is what you need to do: Your checkboxes need to have distinct id attributes. This allows you to connect a <label> to it, using the label’s for-attribute. Example: … Read more

How do I disable right click on my web page?

You can do that with JavaScript by adding an event listener for the “contextmenu” event and calling the preventDefault() method: That being said: DON’T DO IT. Why? Because it achieves nothing other than annoying users. Also many browsers have a security option to disallow disabling of the right click (context) menu anyway. Not sure why you’d want to. … Read more