超链接未在Iframe中打开,而是在新标签页中打开

时间:2013-09-18 05:15:18

标签: html iframe

我在左侧面板侧边栏上有一些超链接。单击其中任何一个时,相应的页面应在右侧的iframe中打开。现在,这对大多数链接都很好。但对于某些链接,不幸的是,我需要使用的链接,它只在第一次页面加载时在iframe中正确打开。之后,它会在新标签页中保持打开状态。

控制台说“不安全的JavaScript尝试使用URL2从带有URL2的帧访问帧。域,协议和端口不匹配。” 但即使在iframe中正确打开链接的情况下也会出现这种情况。我完全不知道为什么会发生这种情况。帮助我。

<a href= "some url" target="iframe_P"> </a>

<iframe src="random url" name="iframe_P" scrolling="auto"></iframe>

我也尝试过使用id =“iframe_P”。也不起作用。

2 个答案:

答案 0 :(得分:0)

看看这个:

 <a href="http://www.wikipedia.org/" target="myIframe">Link Text</a>
    <iframe src="" name = "myIframe"></iframe>

JSFIDDLE

答案 1 :(得分:0)

您应该考虑在模态弹出框中打开iframe。你可以创建一个简单的,你需要的是一篇关于它的文章:

http://www.webdesignerdepot.com/2012/10/creating-a-modal-window-with-html5-and-css3/

这是一个jsfiddle示例: http://jsfiddle.net/tkra4/1/ HTML:     打开模态

<div id="openModal" class="modalDialog">
<div>
    <a href="#close" title="Close" class="close">X</a>
    <h1>Delete this and put your iframe here</h1>
</div>

的CSS:

   .modalDialog {
position: fixed;
font-family: Arial, Helvetica, sans-serif;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0,0,0,0.8);
z-index: 99999;
opacity:0;
-webkit-transition: opacity 400ms ease-in;
-moz-transition: opacity 400ms ease-in;
transition: opacity 400ms ease-in;
pointer-events: none;
}
.modalDialog:target {
opacity:1;
pointer-events: auto;
}

.modalDialog > div {
width: 400px;
position: relative;
margin: 10% auto;
padding: 5px 20px 13px 20px;
border-radius: 10px;
background: #fff;
background: -moz-linear-gradient(#fff, #999);
background: -webkit-linear-gradient(#fff, #999);
background: -o-linear-gradient(#fff, #999);
}
.close {
background: #606061;
color: #FFFFFF;
line-height: 25px;
position: absolute;
right: -12px;
text-align: center;
top: -10px;
width: 24px;
text-decoration: none;
font-weight: bold;
-webkit-border-radius: 12px;
-moz-border-radius: 12px;
border-radius: 12px;
-moz-box-shadow: 1px 1px 3px #000;
-webkit-box-shadow: 1px 1px 3px #000;
box-shadow: 1px 1px 3px #000;
}

.close:hover { background: #00d9ff; }
-webkit-transition: opacity 400ms ease-in;
-moz-transition: opacity 400ms ease-in;
transition: opacity 400ms ease-in;

希望这会有所帮助