javascript - window.open 打开单个链接
问题描述
我正在制作一个学费管理程序,在该程序中我正在处理名为 data.json 的给定 JSON 文件:
{
"9 Standard": [
"https://byjus.com/ncert-solutions-class-9-maths/",
"https://www.google.com/search?q=google+fonts&rlz=1C1CHBD_enIN950IN950&oq=google&aqs=chrome.0.69i59j69i57j69i60j69i65l2j69i60l3.2127j0j7&sourceid=chrome&ie=UTF-8"
],
"9 Applied": [
"https://www.google.com/search?q=google+fonts&rlz=1C1CHBD_enIN950IN950&oq=google&aqs=chrome.0.69i59j69i57j69i60j69i65l2j69i60l3.2127j0j7&sourceid=chrome&ie=UTF-8",
"https://byjus.com/ncert-solutions-class-9-maths/"
],
"10 Standard": [
"https://www.google.com/search?q=google+fonts&rlz=1C1CHBD_enIN950IN950&oq=google&aqs=chrome.0.69i59j69i57j69i60j69i65l2j69i60l3.2127j0j7&sourceid=chrome&ie=UTF-8",
"https://byjus.com/ncert-solutions-class-9-maths/"
],
"10 Applied": [
"https://www.google.com/search?q=google+fonts&rlz=1C1CHBD_enIN950IN950&oq=google&aqs=chrome.0.69i59j69i57j69i60j69i65l2j69i60l3.2127j0j7&sourceid=chrome&ie=UTF-8",
"https://byjus.com/ncert-solutions-class-9-maths/"
],
"11 Standard": [
"https://www.google.com/search?q=google+fonts&rlz=1C1CHBD_enIN950IN950&oq=google&aqs=chrome.0.69i59j69i57j69i60j69i65l2j69i60l3.2127j0j7&sourceid=chrome&ie=UTF-8",
"https://byjus.com/ncert-solutions-class-9-maths/"
],
"11 Applied": [
"https://www.google.com/search?q=google+fonts&rlz=1C1CHBD_enIN950IN950&oq=google&aqs=chrome.0.69i59j69i57j69i60j69i65l2j69i60l3.2127j0j7&sourceid=chrome&ie=UTF-8",
"https://byjus.com/ncert-solutions-class-9-maths/"
],
"12 Standard": [
"https://www.google.com/search?q=google+fonts&rlz=1C1CHBD_enIN950IN950&oq=google&aqs=chrome.0.69i59j69i57j69i60j69i65l2j69i60l3.2127j0j7&sourceid=chrome&ie=UTF-8",
"https://byjus.com/ncert-solutions-class-9-maths/"
],
"12 Applied": [
"https://www.google.com/search?q=google+fonts&rlz=1C1CHBD_enIN950IN950&oq=google&aqs=chrome.0.69i59j69i57j69i60j69i65l2j69i60l3.2127j0j7&sourceid=chrome&ie=UTF-8",
"https://byjus.com/ncert-solutions-class-9-maths/"
]
}
现在,上面的 JSON 文件包含老师想要立即打开以开始上课的链接。所以我试图做出如下安排:
我想做的程序截图
我编写的用于在计算机处理 data.json 数据时创建按钮的代码
<script>
fetch("data.json")
.then((response) => response.json())
.then(function (classes) {
console.log(classes);
Object.keys(classes).forEach(function func(class_data) {
let btn = document.createElement("button");
btn.innerHTML = class_data;
btn.name = class_data;
document.body.appendChild(btn);
btn.className = "button";
btn.onclick = function () {
links = classes[class_data];
links.forEach(func);
console.log(links);
function func(link) {
console.log(link);
window.open(link, class_data);
}
};
});
});
</script>
我希望每个按钮都能打开 2 个窗口,但只有 1 个被打开。因此,根据这个站点,我将window.open(link, class_data);
代码行替换为setTimeout(() => window.open(link), 3000);
,但仍然只打开一个窗口。我对如何克服这个问题感到困惑。请帮帮我。
解决方案
感谢@Lux 的帮助,该程序现在可以运行了。对于那些遇到同样问题的人,我建议他们点击谷歌窗口右上角的 3 个点,然后点击并settings
输入Pop-ups and redirects
。search settings
现在 google 将引导您到可以更改此设置的确切页面,在那里,只需更改Pop-ups and redirects
为Allowed
,现在您会发现 window.open 命令打开多个窗口。
推荐阅读
- solver - 您如何在 Cubical Agda 中使用环求解器?
- python - 动态规划问题的记忆。为什么以下解决方案不起作用?
- java - 如何在以下 lambda exp 中添加同步?
- r - 如何在 ggplot2 中将图例键字形的形状更改为六边形?
- python - 检查两个列表中项目的接近外观 - Python
- c# - 如何使用 Unity 在 iOS 上的下载文件夹中保存文件
- mongodb - Mongodb 聚合 - 在嵌套数组中使用 $addFields 来获取真/假
- objective-c - Metal 计算值与 CPU 值不同
- sql - 使用 peewee 创建子查询,在子查询结果上使用 `.select`
- c# - C# .NET 如何通过 Modbus 从 PLC 连续读取输入