smali-kazmi / detect-mobile-browser

It is a very simple & small javascript lib to detect all major modern mobile browsers in both backend & frontend
72 stars 21 forks source link

UserAgent is null #6

Closed sokraflex closed 9 years ago

sokraflex commented 9 years ago

Hey,

I tested this simply:

<script type="text/javascript" src="js/detect-mobile.js"></script>
<script type="text/javascript">
    console.log(SmartPhone.isAny());
</script>

Result: Cannot read property "match" of null on line 28 in detect-mobile.js

It seems that the "userAgent"-property within the SmartPhone-object is null. The reason is, that (tested under webkit & firefox) console.log(typeof window); prints object and not function, and therefore the user Agent will not be set. I don't know why this bug has not been detected before, but the solution is simple:

On line 111, change:

if(typeof window === 'function') {

to:

if(typeof window === 'function' || typeof window === 'object') {
smali-kazmi commented 9 years ago

@SargTeX good catch thanks for this fix