【发布时间】:2021-02-10 23:04:30
【问题描述】:
我在一个反应组件中有 Iframe,该组件在单击外部 url 按钮时加载一个 pdf 文件(我的 Api 端点,端口为 8000),成功加载后,我想打印该 Iframe 的内容,但是获取和错误
这是我的反应组件
import React from 'react'
const pageCont = () =>{
return(
<div>
<iframe id='pdfp' name='pdfp' src='http://127.0.0.1:8000/api/ebook.pdf'></iframe>
<button onClick={()=>{
document.getElementById("pdfp").contentWindow.focus()
document.getElementById("pdfp").contentWindow.print()}
}>
Print Iframe
</button>
</div>
)
}
export default pageCont;
Uncaught (in promise) DOMException: Blocked a frame with origin "http://127.0.0.1:4100" from accessing a cross-origin frame
我正在从前端发出请求,其 URL 为 127.0.0.1:4100 。我觉得这个错误是由于 iframe 源和请求源具有不同的协议。
【问题讨论】:
标签: javascript reactjs