javascript - user browser detecting information in php

386

I am trying for the long time to search the function that help to find the user browser name. I did my best but not any solution.

If there is not function so tell me How I can send this javascript value to email.

I try to send the a lot of time but it goes in this form userbrowser

while userbroswer should be chrome or something else. I try to use this on Local server without mail it's showing well but when it goes to mail it shows the script instead of information.

Code of js here:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
``<script type="text/javascript">
  $browsers = ["Firefox", "Chrome", "Safari", "Opera", 
                    "MSIE", "Trident", "Edge"];
    $userbrowser 
    $useragent = navigator.userAgent;
    for (var i = 0; i < browsers.length; i++) {
    if( useragent.indexOf(browsers[i]) > -1 ) {
        userbrowser = browsers[i];
        break;
    }
};

switch(userbrowser) {
    case 'MSIE':
        userbrowser = 'Internet Explorer';
        break;

    case 'Trident':
        userbrowser = 'Internet Explorer';
        break;

    case 'Edge':
        userbrowser = 'Internet Explorer';
        break;
     }
</script>
51

Answer

Solution:

for browser Detection, we usenavigator.appName andnavigator.appVersion .navigator.appName detects the web browser andnavigator.appVersion describes the browser version.

var objappVersion = navigator.appVersion;
var objAgent = navigator.userAgent;
var objbrowserName  = navigator.appName;
var objfullVersion  = ''+parseFloat(navigator.appVersion); 
var objBrMajorVersion = parseInt(navigator.appVersion,10);
var objOffsetName,objOffsetVersion,ix;
console.log(objAgent);
console.log(objBrMajorVersion);

if ((objOffsetVersion=objAgent.indexOf("Chrome"))!=-1) {
  objbrowserName = "Chrome";
  objfullVersion = objAgent.substring(objOffsetVersion+7);
}

else if ((objOffsetVersion=objAgent.indexOf("MSIE"))!=-1) {
  objbrowserName = "Microsoft Internet Explorer";
  objfullVersion = objAgent.substring(objOffsetVersion+5);
}


else if ((objOffsetVersion=objAgent.indexOf("Firefox"))!=-1) {
  objbrowserName = "Firefox";
}

else if ((objOffsetVersion=objAgent.indexOf("Safari"))!=-1) {
  objbrowserName = "Safari";
  objfullVersion = objAgent.substring(objOffsetVersion+7);
  if ((objOffsetVersion=objAgent.indexOf("Version"))!=-1) 
    objfullVersion = objAgent.substring(objOffsetVersion+8);
}


if ((ix=objfullVersion.indexOf(";"))!=-1)
  objfullVersion=objfullVersion.substring(0,ix);
if ((ix=objfullVersion.indexOf(" "))!=-1)
  objfullVersion=objfullVersion.substring(0,ix);

objBrMajorVersion = parseInt(''+objfullVersion,10);
if (isNaN(objBrMajorVersion)) {
  objfullVersion  = ''+parseFloat(navigator.appVersion); 
  objBrMajorVersion = parseInt(navigator.appVersion,10);
}
document.write(''
               +'Browser name  = '+objbrowserName+'<br>'
               +'Full version  = '+objfullVersion+'<br>'
               +'Major version = '+objBrMajorVersion+'<br>'
               +'navigator.appName = '+navigator.appName+'<br>'
              )



People are also looking for solutions of the problem: your lock file does not contain a compatible set of packages. please run composer update
Source

Share


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.


Similar questions

Find the answer in similar questions on our website.

174 javascript - user browser detecting information in php
733 php - How to show users that a new comment has been entered
56 Pass variable from PHP to Javascript without showing in HTML
558 Exporting php in a same file as html to use css (PHP issue!)
528 javascript - AngularJS + PHP. Login panel
575 How do I clear a result and prepare for the next in javascript/php
993 php - Websockets control user access
899 php - MySQL Access violation in Laravel that works in phpmyadmin
820 implementation - Unable to paste PHP code into HTML section of PHP document?
599 php - how to execute a javascript function returned from ajax response

People are also looking for solutions to the problem: php - esponse to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin'

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.