Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 非常简单的平板电脑重定向_Javascript_Html - Fatal编程技术网

Javascript 非常简单的平板电脑重定向

Javascript 非常简单的平板电脑重定向,javascript,html,Javascript,Html,我正在使用一个非常简单的HTML网站,需要重新定向到平板电脑和手机的单独URL。我有手机与以下工作。我是否可以补充一些不太复杂的东西,让它也适用于平板电脑 <script type="text/javascript"> <!-- if (screen.width <= 699) { document.location = "https://www.londonontariomortgages.ca/m/index.html"; } //--> </script

我正在使用一个非常简单的HTML网站,需要重新定向到平板电脑和手机的单独URL。我有手机与以下工作。我是否可以补充一些不太复杂的东西,让它也适用于平板电脑

<script type="text/javascript">
<!--
if (screen.width <= 699) {
document.location = "https://www.londonontariomortgages.ca/m/index.html";
}
//-->
</script>

您可以尝试使用
navigator.userAgent
Regex
检查用户设备

函数Init(){
if(/Android | iPhone | iPad/i.test(navigator.userAgent)){
//移动设备
document.location=”https://www.londonontariomortgages.ca/m/index.html";
}否则{
document.location=”https://stackoverflow.com/questions/50994561/very-simple-redirect-for-tablet/50994679?noredirect=1#";
}
}

Init()您可能需要使用
mobiledetect
软件包

编写器需要mobiledetect/mobiledetectlib


现在你不需要检查特定的设备。为什么?因为有太多的东西无法跟踪

这就是为什么要检查功能以相应地采取行动

您还可以使您的网站具有响应性。看一看。 通过使用此选项,您可以将站点配置为“如果屏幕为中等大小,则将其放在那里”(它们具有标准断点以确定屏幕是否为大屏幕等,这一点被广泛使用)

编辑


要实际检测设备类型:“平板电脑”与“笔记本电脑”有何不同?(提示:它不是)你真的应该考虑响应设计。单独的移动网站维护起来非常痛苦,而且对用户来说往往是一种糟糕的体验。很抱歉-我真的很不擅长-我是否只需要将其复制并粘贴到index.html的头部部分?@MarkMitchell我添加了完整的代码,您可以将其粘贴到脚本标记中。我想我做到了:)谢谢-我已经制作了移动/平板网站,以及我原来的网站-所以我只需要重新-direct@MarkMitchell添加了设备类型检测脚本的链接
$detect = new Mobile_Detect;
// any mobile devices
if ( $detect->isMobile() ) {
  // do something for mobile users
}

// Any tablet device.
if( $detect->isTablet() ){
 // do something for tablet users
}