---
# System prepended metadata

title: 從FB或LINE開啟瀏覽器時，將跳轉開啟原生瀏覽器
tags: [javascript, 網站開發]

---

~~~javascript
var u = navigator.userAgent,
  ua = navigator.userAgent.toLowerCase();
let isLineApp = u.indexOf("Line") > -1 ? true : false; // Line 內建瀏覽器
let isFbApp = u.indexOf("FBAV") > -1 ? true : false; // FB App 內建瀏覽器

if ((isLineApp || isFbApp) && !window.location.href.includes('openExternalBrowser')) {
  var currentUrl = window.location.href;
  var redirectUrl = currentUrl.indexOf('?') > -1 ? currentUrl + '&openExternalBrowser=1' : currentUrl + '?openExternalBrowser=1';
  window.location.href = redirectUrl;
}
~~~