check whether browser is chrome or edge

前端 未结 4 1703
天命终不由人
天命终不由人 2021-01-01 18:57

My current website runs only in Chrome browser, to do this I have checked in following way

if (Request.Browser.Browser == \"Chrome\")
{
   // Allow
}
         


        
4条回答
  •  再見小時候
    2021-01-01 19:06

    You can check user-agent and see whether it is Microsoft Edge or not because Microsoft Edge contains Edge/version in it's user-agent string.

    //get user agent somehow here based on what you are working on
    userAgent = Request.UserAgent;
    
    if (userAgent.IndexOf("Edge") > -1)
    {
       // maybe client's browser is Microsoft Edge
    }
    

    sample of Edge user-agent strings

    Mozilla/5.0 (X11; CrOS x86_64 6783.1.0) AppleWebKit/537.36 (KHTML, like Gecko) Edge/12.0

    See more here and here

    At the end I suggest to use feature detection on browser instead of acting based on user-agent.

提交回复
热议问题