javascript - 当我尝试使用 JS/JQuery 在新窗口中写入时出现问题
问题描述
我对 jQuery/JavaScript 的加载有问题,我想在单击带有特定数据的按钮后尝试在新窗口中写入,这些数据保存在变量event.target.dataset.serial
中,但我不知道为什么我不能在新窗户
bindNewWindow(handler) {
$('.container p button').click((event) => {
let position = this.newWindow.length;
this.newWindow[position] = window.open('window.html', position, "width=1100, height=600, top=250, left=250, titlebar=yes, toolbar=no, menubar=no, location=yes");
this.newWindow[position].addEventListener('DOMContentLoaded', () => {
handler(event.target.dataset.serial)
});
this.newWindow[position].focus();
event.preventDefault();
event.stopPropagation();
});
}
MostrarImagenVentanaNueva(imagen) {
//Aquí iría la condición de si la ventana ya existe
let position = this.newWindow.length - 1;
let main = $(this.newWindow[position].document).find('main');
main.empty();
let container = $(`
<img width="250px" height="250px" src="${image.getURL()}"</p>
<p>${image.getTitle()}</p>
<p>${image.getDescription()}</p>
<p>${image.getCoords()}</p>
`);
main.append(container);
this.newWindow[position].document.body.scrollIntoView();
}
解决方案
推荐阅读
- scala - 将字符串插值器宏包装在另一个中
- docker - 使用 docker hub 时如何强制 docker-compose 下载新图像?
- javascript - 使用 javascript 创建一个可点击的圆圈 10 次,如果我点击它,它会在中心显示数字我点击了多少次
- c# - 发生了“System.StackOverflowException”类型的未处理异常,并且 toString 首先出现了几个不同的问题
- dart - 使用 IMAP 将所有电子邮件放入列表
- sql - 用于复制过程的多表组插入
- javascript - MS Edge 在浏览器最小化时阻止脚本执行
- laravel - 下载使用 laravel 5.4 中的存储外观存储的文件
- c# - MSTest 断言失败,引用为空
- javascript - 如何在客户端机器上获得屏幕缩放?