强制Android用户使用Google Chrome或Safari访问网站



我们做了一个针对Google Chrome/Safari优化的网络应用程序。我想

  • 强制所有安卓用户使用谷歌浏览器访问该网站。如果Chrome不可用,我不希望他们访问该网站。
  • 强制所有 iOS 用户使用 Safari 浏览器

你能向我建议正确的方法吗?

谢谢

我想我有一个简单的解决方案给你。

首先,您需要检查他们使用的浏览器,然后如果他们没有使用你们优化的 2 种浏览器之一,则需要将他们定向到 chrome 或 safari。

所以:

// Opera 8.0+
var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
// Firefox 1.0+
var isFirefox = typeof InstallTrigger !== 'undefined';
// Safari 3.0+ "[object HTMLElementConstructor]" 
var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || (typeof safari !== 'undefined' && safari.pushNotification));
// Internet Explorer 6-11
var isIE = /*@cc_on!@*/false || !!document.documentMode;
// Edge 20+
var isEdge = !isIE && !!window.StyleMedia;
// Chrome 1 - 71
var isChrome = !!window.chrome && (!!window.chrome.webstore || 
!!window.chrome.runtime);
// Blink engine detection
var isBlink = (isChrome || isOpera) && !!window.CSS;

上面的代码将分配布尔值 true(如果它们在该浏览器上(和 false(如果它们不在(。

现在您可以决定该怎么做,因为您知道他们正在使用什么浏览器

// If they are not on chrome and safari
if (!isChrome && !isSafari) {
    // replace this with whatever you want to do
    // in this case I make your website text red, but you could display a link 
    // to chrome app in playstore or whatever you need
    document.getElementByTagName("body").style.color = "red";
}

最新更新