In my case, the problem was that I was unknowingly loading jQuery twice. When jQuery loads, it appears that it creates a new jQuery
object from scratch, which has the effect of deleting all custom properties already set on the jQuery
object.
To find the source of the problem, I moved this code around the page until I found the first line after which it started saying jQuery.browser.mobile
was undefined
:
<script>
alert("in script tag in middle: jQuery.browser.mobile === " + jQuery.browser.mobile);
</script>
The line was this:
<!--#include file="include/set_hm.inc"-->
That line included a file that contained this line, loading jQuery:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
If I delete that line, then jQuery.browser.mobile
keeps its value as it should.
To fix my problem with jQuery.browser.mobile, I just need to make sure the plugin is loaded after jQuery. I could do this by extracting the jQuery inclusion from that included file, or by moving the plugin loading to after the file inclusion.