首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >仅对桌面设备重定向

仅对桌面设备重定向
EN

Stack Overflow用户
提问于 2022-03-19 19:50:51
回答 1查看 40关注 0票数 1

我正在尝试重定向桌面设备更改脚本:

代码语言:javascript
复制
if (screen.width <= 699) {
  document.location = "Other URL";
}

699到主要宽度,但不能工作。请问如何才能做到重定向?我的目的是只为桌面,但我有成功,只有移动。艾比建议?

EN

回答 1

Stack Overflow用户

发布于 2022-03-19 20:16:02

下面是在现代浏览器版本上使用ECMA6 works的脚本。也可以为桌面设备裁剪页面。

代码语言:javascript
复制
var isMobile = navigator.userAgent.toLowerCase().indexOf('mobile') > -1;
var getChromeVersion = function() {
  var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
  return raw ? parseInt(raw[2], 10) : false;
};


console.log('isMobile :' + isMobile)
console.log('getChromeVersion :' + getChromeVersion())

if (isMobile == false) {
// if device is desktop then redirect our page
 window.location.replace("https://maximumroulette.com");
 // OR
 // window.location.href = "https://www.google.com";
}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71541531

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档