[英]links within an iframe window to open in new tab
我已经多次看过这个问题了,很多答案似乎都暗示了基础target="_blank"
技术。 但是,我以前用过这个; 但我目前的页面不起作用。 即使它确实奏效,我也认为它不是最好的选择; 因为我只想在iframe src=""
的链接在新窗口中打开。 我正在跳过一个简单的解决方案,我可以在页面中添加内联。 我也尝试添加如下ID,并使用JavaScript,仍然是虚无...
<iframe src="mywordpressfeed.html" id="frame1" width="310" height="380"></iframe>
JS
$(document).ready(function(){
$("#frame1").attr("target","_blank");
});
基本上,目标是当用户在静态页面上的iframe中看到我的wordpress提要时; 一旦点击了帖子标题,它就会在新窗口中加载 - 因为它现在加载在同一个iframe中,因此没有提高可读性的水平。
由于iFrame标签是针对相反的,因此没有真正的解决方案。
//pass the iframe to this iframe getting function
function iframeRef( frameRef ) {
return frameRef.contentWindow ? frameRef.contentWindow.document : frameRef.contentDocument
}
//Get Iframe
var inside = iframeRef( document.getElementById('iframeID') );
//Get all links
var links = inside.getElementsByTagName('a');
//Loop throught links and set their attributes
for (var i = 0 ; i<links.length ; i++){
links[i].setAttribute('target','_blank');
}
//No jQuery needed!
感谢meder
编辑由于iframe相同的源限制,我必须找到一个内部iframe来自同一来源的网站,以便您可以粘贴此代码
//pass the iframe to this iframe getting function
function iframeRef( frameRef ) {
return frameRef.contentWindow ? frameRef.contentWindow.document : frameRef.contentDocument
}
//Get Iframe
var inside = iframeRef( document.getElementById('IFwinEdit_Gadget_247730_3349') );
//Get all links
var links = inside.getElementsByTagName('input');
//Loop throught links and set their attributes
for (var i = 0 ; i<links.length ; i++){
links[i].setAttribute('style','background:red');
}
//No jQuery needed!
到这个网站的控制台,看到输入改变颜色
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.