Posts Tagged ‘javascript’

jQuery mobile page duplication

Saturday, May 12th, 2012

We decided to use jQuery mobile for a recent project and were very happy with the results until we ran into a weid issue with the ajax loading. It appears that whatever page you come into the site on will hold onto it’s content no matter what. This becomes an issue when you link back to that page. Depending on the situation you may or may not end up with duplicate content getting dynamically injected into the page. Where this gets sticky is that if you are trying to get an element by it’s id you might get he shown content or some sort of hidden cached content. It seems to vary from situation to situation, but we kept having all the javascript in our homepage break. Our solution ended up being to set $.mobile.ajaxEnabled = false; which essentially breaks what we were trying to use the framework for.

Scoping in javascript

Monday, October 11th, 2010

Not sure why I don’t see more addressing this on the internet, but when you make an object in javascript and want to call the methods it contains via event listeners all the method calls fall out of scope, making instance variables out of scope as well. I have done all kinds of weird things to get around this in the past, until one of my coworkers set me up with this method:

function CreateDelegate(object, method) {
return (function() { return method.apply(object, arguments); })

Nice to have easy to use and light. I don’t need to import any external libraries.