Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在打印 iframe 内的内容时遇到了问题。
这是 iframe 之外的锚标记:
<a href=”#” onclick='window.print()' >Print</a>
这是我的 iframe
<iframe name="newtest" src="https:xyz.com" ></iframe>
我想在点击 iframe 外部的锚标记时打印 iframe 内部的页面
<iframe src="" id="iframeid"></iframe> document.getElementById("iframeid").contentWindow.print();
如果您尝试打印远程站点,则无法以任何方式进行。
如果您是http://yoursite.org并且 iframe 是<iframe src="http://google.com">您不能这样做,则站点域必须匹配
http://yoursite.org
<iframe src="http://google.com">
相反,如果该页面是本地页面<iframe src="page.htm">,它将起作用
<iframe src="page.htm">