Tag: javascript

Escape strings for use in JavaScript

When using parameters from the URL, it should always be sanitized before using it in your javascript. Using jQuery you can easily do: var safeString = $(“<span></span>”).text(unsafeString).html(); Using plain javascript: var entityMap = { “&”: “&amp;”, “<“: “&lt;”, “>”: “&gt;”,

Posted in Coding Tagged with: , ,

iPad textarea not selectable

Problem The textarea on iPad could not be selected and could not have anything entered. Solution The textarea in iPad only responds to the ‘touchstart’ event and not the ‘click’ event, but regular input accepts the ‘click’ apparently.  I some javascript where it would catch

Posted in Coding Tagged with: , ,

Best way to detect Retina with Javascript

Best way according to W3C standards: http://stackoverflow.com/questions/19689715/what-is-the-best-way-to-detect-retina-support-on-a-device-using-javascript

Posted in Coding Tagged with: ,

WordPress Heartbeat API

I could not find any extensive documentation on the WordPress Heartbeat API, so I am writing here to remember what I have learned through various tutorials throughout the web. The Heartbeat API is written in Javascript.  Think of it like a

Posted in Coding Tagged with: , ,

Bootstrap Tab linking

If you use Bootstrap (v3.x) you would see that clicking on a tab does add anything to the url so if you were to refresh, you wouldn’t go back to the tab you are on.  The post below says to

Posted in Coding Tagged with: , ,

Javascript defaultValue

For some reason I have never needed to use the defautlValue property up until today.  I was pleased to find javascript can access the original input value so tracking changes in a form is a bit easier.  However, the defaultValue

Posted in Coding Tagged with: ,

Fancybox not working after second click

Problem Setting up fancybox 1.3.4 with inline content doesn’t work when clicking on the link twice. Solution The problem I think is with the upgraded version of jQuery.  If using jQuery 1.4 like the example, it should work fine.  But

Posted in Coding Tagged with: ,

IE Doesn’t see padding on hover

Problem Internet Explorer 8 (I no longer even look at IE 7) seems to not be able to see the padding on an anchor tag within a ul > li > a structure.   Using jQuery I have a hover

Posted in Coding Tagged with: , , ,

jQuery – When to use return false or preventDefault

Ran into a great article that explains the differences between return false, preventDefault and stopPropagation.  Here’s a summary: return false does both preventDefault and stopProgagation preventDefault just stops the browser default event. stopPropagation stops bubbling. In most cases you would

Posted in Coding Tagged with: ,

WordPress Widget Image Field

I found a great utility plugin to help with adding a Image picker field to a widget.  Basically you install and activate this plugin and you make your own widget and utilize the image field easily. The only problem I

Posted in Coding Tagged with: , ,