要讓點擊連結時於 iframe 內開啟,必須讓 a 標籤的 target 對應 iframe 的 name(而非 id):
<iframe id="myFrameId" name="myFrameName" scrolling="no" frameborder="0" style="width:200px; height:150px;"></iframe> <a href="../ashx/Print2DCodeImage.ashx?codeInfo=Demo123" target="myFrameName">列印二維碼</a>
重點在於 target 指向的是 name 為 myFrameName 的 iframe,而非用 id 作為目標。若寫成 target="myFrameId",只有新版 Chrome、Opera 支援,在 IE10、Firefox 中都不生效。