In Django, we already have session details stored in django_session and last_login in the auth_user table. However, I am interested in storing the browser name when a user logs in using their browser in the database.
Currently, I can retrieve the browser name from the active browser on the frontend page using JavaScript, but I want to save this information in the database.
I hope to achieve saving the active browser name in the database as the output.
Below is the snippet of my JavaScript code:
<html>
<body>
<div id="demo"></div>
<script>
let browserName = "";
if(navigator.vendor.match(/google/i)) {
browserName = 'Browser Name: Google Chrome';
}
else if(navigator.vendor.match(/apple/i)) {
browserName = 'Browser Name: Apple Safari';
}
else if(navigator.userAgent.match(/firefox\//i)) {
browserName = 'Browser Name: Mozilla Firefox';
}
else if(navigator.userAgent.match(/edge\//i)) {
browserName = 'Browser Name: Microsoft Edge';
}
else if(navigator.userAgent.match(/trident\//i)) {
browserName = 'Browser Name: Internet Explorer';
}
else
{
browserName = navigator.userAgent + "\n" + navigator.vendor;
}
</script>
<h2><script type="text/javascript">document.write(browserName)</script></h2>
</body>
</html>