IS there a way to automatically recognize the browser? Example, our website use IE 11 as main and migrated to MS Edge. But, some computers are still on Windows XP and Windows7 and doesn't support Edge redirect. So, I wanna know is detact the browser and if Edge is not supported, continue on using IE11.
CodePudding user response:
Many browsers send a User-agent
header with their HTTP request, which your webserver (and potentially any webapplications that are attached behind it) can read.
For illustration, if you press F12 to open your browsers devtools, go to the network tab, then browse to, or refresh any website, you'll see a list of all http connections there. click on any of them and you'll be able to see the individual headers for both the outgoing request and incoming response (which likely includes the User-agent)
CodePudding user response:
As already mentioned, you can use the user-agent
to detect which browser you are using. Use simple javascript code to achieve such a function, a simple example (IE and Edge):
// Internet Explorer 6-11
var isIE = /*@cc_on!@*/false || !!document.documentMode;
// Edge 20
var isEdge = !isIE && !!window.StyleMedia;
// Edge (based on chromium) detection
var isEdgeChromium = isChrome && (navigator.userAgent.indexOf("Edg") != -1);
For more browser detection, you can refer to the answer in this thread.