Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.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_Redirect - Fatal编程技术网

Javascript 按浏览器窗口的宽度重定向到其他页面

Javascript 按浏览器窗口的宽度重定向到其他页面,javascript,html,redirect,Javascript,Html,Redirect,我使用xampp运行代码,当我访问html文件(使用Firefox)时,即使我的浏览器宽度超过1400,我也会被重定向 这是我的html代码: <!DOCTYPE HTML> <html lang="en-us"> <head> <title>Packet</title> <script src="my.js"></script> </head> <body> <h1> H

我使用xampp运行代码,当我访问html文件(使用Firefox)时,即使我的浏览器宽度超过1400,我也会被重定向

这是我的html代码:

<!DOCTYPE HTML>
<html lang="en-us">

<head>
<title>Packet</title>
<script src="my.js"></script>
</head>

<body>
<h1> Hello, Paul! </h1>
</body>

</html>

小包裹
你好,保罗!
这是我在“my.js”文件中的javascript代码:

if(screen.width尝试使用:

window.innerWidth
而不是
screen.width

这样就可以了!

尝试使用:

window.innerWidth
而不是
screen.width


这应该就够了!

屏幕。width
返回显示器的宽度,而不是文档的宽度

document.width
用于此目的

if (document.width <= 1400) {
    window.location = "mobile";
}

if(document.width
screen.width
返回显示器的宽度,而不是文档的宽度

document.width
用于此目的

if (document.width <= 1400) {
    window.location = "mobile";
}

if(document.width
screen.width
返回什么?控制台记录它而不是
window.location
screen
-huh,它是什么?straw,如果screen.width小于1400,则自动重定向到移动文件夹screen是浏览器的窗口
screen.width
属性返回用户屏幕的总宽度,单位为像素Els什么是
screen.width
返回?控制台记录它而不是
窗口。位置
screen
-嗯,它是什么?straw,如果screen.width小于1400,则自动重定向到移动文件夹screen是浏览器的窗口
screen.width
属性返回用户屏幕的总宽度,以像素为单位re您的屏幕没有变大?尝试将值更改为1您确定屏幕没有变大吗?尝试将值更改为1非常感谢!非常感谢!