Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi everyone

How to detect browser in html without javascript
Just html code
I want redirect user if use IE to Chrome
Or Show message to user

is disable by proxy
please Help me ..
thanks

<b>What I have tried:</b>

<script type="text/javascript">
let x=0;
document.addEventListener("DOMContentLoaded", function (event) {
if (IECheck() && x==0 ) {
let msg = "مرورگر شما پشتیبانی نمی شود لطفا با مرورگر" ;
msg =msg + "\n" ;
msg =msg + " Chrome " ;
msg =msg + "\n" ;
msg=msg +" اجرا نمایید ";
// <meta http-equiv="refresh" content="1; URL=http://localhost:4200/assets/NotSupported.html" />

window.location.href = "./assets/NotSupported.html";

x=1;
}
});

function IECheck() {
var ua = window.navigator.userAgent;

var msie = ua.indexOf('MSIE ');
var ie11 = ua.indexOf('Trident');
return msie > 0 || ie11 > 0;
}
Posted
Updated 9-Apr-22 19:18pm

Pure HTML can't do that - it's a "static text" based format, and has no real processing ability.
Normally you would do this an Javascript, but it is possible to access the UserAgent string in the code behind which serves the HTML to the client browser. For example: HttpRequest.UserAgent Property (System.Web) | Microsoft Docs[^]

But ... be aware it is very easy to "spoof" a UserAgent string - I ran for years with my browser reporting it used LCARS[^] instead of Chromium ...
 
Share this answer
 
Comments
Richard Deeming 7-Apr-22 5:15am    
Even if you don't explicitly spoof it, the user agent is notoriously unreliable:
WebAIM: History of the browser user-agent string[^]
thank you
I change my script code and change location to body
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900