js如何检测电脑显示器个数并投屏到指定显示器打开网页?
网友回复
参考这个代码
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>显示器检测与窗口定位</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
line-height: 1.6;
color: #333;
max-width: 800px;
margin: 2rem auto;
padding: 0 1rem;
}
h1, h2 {
color: #1a1a1a;
}
#detectButton {
background-color: #007bff;
color: white;
border: none;
padding: 10px 20px;
font-size: 16px;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
#detectButton:hover {
background-color: #0056b3;
}
#detectButton:disabled {
background-color: #cccccc;
cursor: not-allowed;
}
#info {
margin-top: 2rem;
padding: 1rem;
background-color: #f8f9fa;
border: 1px solid #dee2e6;
border-radius: 5px;
}
.screen-card {
border: 1px solid #ccc;
border-radius: 8px;
padding: 15px;
margin-bottom: 15px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.screen-card h3 {
margin-top: 0;
color: #0056b3;
}
.screen-card button {
margin-top: 10px;
background-color: #28a745;
color: white;
border: none;
padding: 8px 15px;
border-radius: 4px;
cursor: pointer;
}
.screen-card button:hover {
background-color: #218838;
}
.error {
color: #dc3545;
font-weight: bold;
}
.notice {
font-size: 0.9em;
color: #6c757d;
}
</style>
</head>
<body>
<h1>JavaScript 显示器检测与窗口定位</h1>
<p class="notice">注意:此功能需要使用Chrome或Edge等现代浏览器,并且需要在HTTPS安全环境下运行。首次点击时,浏览器会请求“窗口管理”权限。</p>
<b...点击查看剩余70%


