Detect the user's browser and Redirect

Detect the user's browser and Redirect
Get Started > Details
  • Details
  • Install

Deskripsi.

Ini merupakan Request dari Dida. kode ini mendeteksi pengguna atau user sedang menggunakan browser apa dan mengarangkan ke url yang sudah kita tentukan jika browser yang digunakan tidak diijinkan.

Cara meng-install.

  • Salin kode ini
    let userAgent = navigator.userAgent;
    if(userAgent.match(/edg/i)){
      //browser edge
      window.location.href = 'https://www.rasgane.com/';
    }else if(userAgent.match(/firefox|fxios/i)){
      //browser firefox
      window.location.href = 'https://www.rasgane.com/';
    }else if(userAgent.match(/brave/i)){
      //browser Brave
      window.location.href = 'https://www.rasgane.com/';
    }else if(userAgent.match(/opr\//i)){
      //browser opera
      window.location.href = 'https://www.rasgane.com/';
    }else if(userAgent.match(/chrome|chromium|crios/i)){
      //browser chrome
      window.location.href = 'https://www.rasgane.com/';
    }else if(userAgent.match(/safari/i)){
      //browser safari
      window.location.href = 'https://www.rasgane.com/';
    }else{
      //browser other
      alert("Other browser");
    }
  • Bungkus kode dengan
    <script>//<![CDATA[
      // Kode Javascript Is Hire
    //]]></script>
  • Letakkan di atas </body>
Name Deskripsi Example
URL Isi dengan URL tujuan pengalihan(Redirect). https://www.rasgane.com
Referensi :
https://www.youtube.com/watch?v=OX2mvhFUoYM
https://www.codingnepalweb.com/detect-browser-in-javascript/
https://www.w3schools.com/js/js_window_location.asp

Comments

  1. Thank you but when I use Brave, I can still view the website.

    ReplyDelete