鍍金池/ 問答/HTML/ vue頁面瀏覽器判斷

vue頁面瀏覽器判斷

vue寫的頁面,ie等其他瀏覽器都兼容性不好。 如何在打開首頁面時判斷瀏覽器,提示用戶使用chrome瀏覽器訪問?謝謝!

回答
編輯回答
冷溫柔

index.html 頁面

<!--[if IE]>
<script>
//....你要執(zhí)行的代碼 是想alert 還是跳轉提示頁面什么的自己定
</script>
<![endif]-->

2017年7月16日 07:53
編輯回答
乖乖噠

或者加上該加的polyfill

App.vue里面:

<script>
import "babel-polyfill";
export default {
  name: "app"
};
</script>

2017年7月27日 19:21
編輯回答
終相守
    var userAgent = navigator.userAgent; //取得瀏覽器的userAgent字符串
    var isOpera = userAgent.indexOf("Opera") > -1;
    if (isOpera) {
        return "Opera"
    }; //判斷是否Opera瀏覽器
    if (userAgent.indexOf("Firefox") > -1) {
        return "FF";
    } //判斷是否Firefox瀏覽器
    if (userAgent.indexOf("Chrome") > -1){
  return "Chrome";
 }
    if (userAgent.indexOf("Safari") > -1) {
        return "Safari";
    } //判斷是否Safari瀏覽器
    if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {
        return "IE";
    }; //判斷是否IE瀏覽器
}

//以下是調(diào)用上面的函數(shù)
var mb = myBrowser();
if ("IE" == mb) {
    alert("我是 IE");
    
    // 在這里給出提示
}
2017年9月1日 22:49
編輯回答
只愛你
html 部分:
 <p v-if="isShowChromeTip" style="color: red;font-size: 15px; margin-top: -30px;text-align:center">請務必使用Chrome瀏覽器打開【<a target="_blank" >點擊下載</a>】</p>



script部分
 computed: {
    isShowChromeTip() {
      const USER_AGENT = navigator.userAgent.toLowerCase()
      const isChrome = /.*(chrome)\/([\w.]+).*/
      return !isChrome.test(USER_AGENT)
    }
  }

2017年12月28日 20:12