首页 > 解决方案 > 当我尝试使用 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();
}

标签: javascriptjquery

解决方案


推荐阅读