【问题标题】:Is it possible to open a new window and embed iframe in to this?是否可以打开一个新窗口并将 iframe 嵌入其中?
【发布时间】:2013-12-12 16:47:25
【问题描述】:

我需要打开一个新窗口,我想在 iframe 中嵌入视频并在此窗口中显示。正常的弹出窗口语法是:

window.open(URL,name,specs,replace)

我将如何传递 iframe 代码而不是 URL,以便 iframe 嵌入到新窗口中?请提出建议。

提前致谢。

【问题讨论】:

    标签: javascript html iframe popup window.open


    【解决方案1】:

    您没有将 iframe 代码传递给 window.open,而是在您正在打开的窗口上获得一个句柄并将 iframe 写入该窗口。

    var win = window.open();
    win.document.write('<iframe width="560" height="315" src="//www.youtube.com/embed/mTWfqi3-3qU" frameborder="0" allowfullscreen></iframe>')
    

    【讨论】:

    • 我想要与 PDF 文档相同的功能我只是将 src 替换为 pdf 内容但不起作用
    • @AbdulHameed 您想要弹出窗口内 iframe 中的 pdf 文件吗?如果是这样,它应该与 iframe 中的 YouTube 链接相同,我建议检查 pdf 文件的路径是否正确
    • var string = doc.output('datauristring'); var iframe = "" var x = window.open(); x.document.open(); x.document.write(iframe); x.document.close(); //使用这个@AbdulHameed
    • window.open() 当前在 Chrome 上返回 null,因此您提供的解决方案已过时
    • @Necroqubus 不确定您运行的是哪个版本的 Chrome,但它在当前版本上运行良好 - 版本 70.0.3538.110(官方构建)(64 位)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-11
    • 1970-01-01
    相关资源
    最近更新 更多