Uncaught ReferenceError: google is not defined when trying to use Google Places API without a map

From my reading, async and defer aren’t meant to be used at the same time. While your <script> that loads the API from google is deferred, your <script> with your code is not deferred. (If you remove async and defer your code works, but is theoretically slower.) If you defer your code execution until the document is loaded (and the google api instantiated), then your code should … Read more

Why is “forEach not a function” for this object?

bject does not have forEach, it belongs to Array prototype. If you want to iterate through each key-value pair in the object and take the values. You can do this: Usage note: For an object v = {“cat”:”large”, “dog”: “small”, “bird”: “tiny”};, Object.keys(v) gives you an array of the keys so you get [“cat”,”dog”,”bird”]

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

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