Javascript 按浏览器窗口的宽度重定向到其他页面
我使用xampp运行代码,当我访问html文件(使用Firefox)时,即使我的浏览器宽度超过1400,我也会被重定向 这是我的html代码: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
<!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.widthscreen.width
返回显示器的宽度,而不是文档的宽度
有document.width
用于此目的
if (document.width <= 1400) {
window.location = "mobile";
}
if(document.widthscreen.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非常感谢!非常感谢!