-3
function get_browser() {
    var N = navigator.appName, ua = navigator.userAgent, tem;
    var M = ua.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i);
    if (M && (tem = ua.match(/version\/([\.\d]+)/i)) !== null)
              M[2] = tem[1];
    M = M ? [M[1], M[2]] : [N, navigator.appVersion, '-?'];
    return M[0];

}

*Its edited and no longer a Question *

1 Answers1

1

The problem is that you don't ever assign a value to tem, so tem[1] is essentially saying undefined[1]. Hence the error.

Change

if (M && (tem === ua.match(/version\/([\.\d]+)/i)) !== null)

to

if (M && (tem = ua.match(/version\/([\.\d]+)/i)) !== null)

That is, change the === comparison to an assignment.

And then rethink why it is you "need" to know which browser the user has.

nnnnnn
  • 147,572
  • 30
  • 200
  • 241
  • i need to know because i want to run my application just latest version or currently i am not supporting mobile or IE.thats why i want to get browser or browser version – Muhammad kashif Hanif Jan 09 '15 at 06:38