18910140161

JavaScript-如何创建包含文本和图像的新窗口-堆栈溢出

顺晟科技

2022-10-18 12:17:07

148

这是我的代码,我想在下面添加一张图片:

function createWindow() {
    var myWindow = window.open("", "MsgWindow", "width=500,height=500");
    myWindow.document.write("<h1>A test: </h1>" + 
    " <p> <b>Something bold: </b> text </p>");
    // I want to add an image here (inside the widow) but I'm not sure how

}

顺晟科技:

function createWindow() {
  const myWindow = window.open('', 'My New Window', 'width=500,height=500')
  myWindow.document.body.innerHTML = `
    <h1>A test:</h1>
    <p> <b>Something bold: </b> text </p>
    <img src="https://i.imgur.com/qVr8o7q.jpeg" />
  `;
}

您可以将图像添加到myWindow的HTML文档中,如下所示:

myWindow.document.write("<img src='https://i.imgur.com/RUKhJjI.png' width=256 height=256>");
  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航