[英]HTML & Javascript : Open link in new tab
我對forumactif的代碼有一點問題。 這不是我自己的工作,所以我完全不了解這種編碼方式了……這是一個HTML頁面( http://www.endrothroad.net/h7-page-d-accueil )並在滾動框中提供了鏈接無法在新標簽頁中打開。 最重要的是,我無法再更改此框中的文本樣式。 因此,這是HTML頁面的代碼。
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type" />
<title>Dernier sujet</title><base target="_parent" /> <style>
h1{
text-align: center;
font-size:14px;
color: #dd3d3d;
font-family: Trajan Pro;
width: 175px;
}
a{
text-decoration:none;
color:#ffffff !important;
font-weight:bold;
}
a:hover{
color:#ffffff !important;
}</style>
<div style="margin:-10px;">
<h1>
Derniers messages
</h1>
<div style="margin-top: -10px; width: 175px; height: 80px; font-size: 10px; font-family: arial;" id="dernier_sjt">
<iframe onload="var frame_sjt=window.frame_sjt.document.getElementById('comments_scroll_div');console.log(frame_sjt);document.getElementById('dernier_sjt').innerHTML=frame_sjt.innerHTML;$('.marquee').marquee();" src="/portal.forum" name="frame_sjt"> </iframe>
</div><script src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"></script><script src="https://illiweb.com/rs3/30/frm/jquery/marquee/jquery.marquee.min.js" type="text/javascript"></script>
</div>
我嘗試了一個簡單的“ _blank”,但顯然不起作用...如果有人可以幫助我,那就太好了! TY
據歐陽霍夫曼的問題(如何使在iframe在新標簽中打開?所有鏈接) ,你可以使用jQuery給所有a
元素的目標blank
或選擇每a
與香草的Javascript,其中兩個解決方案將打開所有元素新標簽中的鏈接。
注意 :由於網站的行為,這並不跨越iFrame來源中的域。
jQuery (您正在使用v1.4.2): $('a').setAttribute('target','_blank');
$('a').setAttribute('target', '_blank');
h1 { text-align: center; font-size: 14px; color: #dd3d3d; font-family: Trajan Pro; width: 175px; } a { text-decoration: none; color: #ffffff !important; font-weight: bold; } a:hover { color: #ffffff !important; }
<script src="https://illiweb.com/rs3/30/frm/jquery/marquee/jquery.marquee.min.js"></script> <script src="http://code.jquery.com/jquery-1.4.2.min.js"></script> <div style="margin:-10px;"> <h1> Derniers messages </h1> <div style="margin-top: -10px; width: 175px; height: 80px; font-size: 10px; font-family: arial;" id="dernier_sjt"> <iframe onload="var frame_sjt=window.frame_sjt.document.getElementById('comments_scroll_div');console.log(frame_sjt);document.getElementById('dernier_sjt').innerHTML=frame_sjt.innerHTML;$('.marquee').marquee();" src="http://www.endrothroad.net/h7-page-d-accueil/portal.forum" name="frame_sjt"></iframe> </div> </div>
Javascript : window.frames["iFrame"].getElementsByTagName("a")[0].target="_blank";
您需要將id="iFrame
添加到您的iFrame中,以便像下面的示例中那樣引用iFrame。
window.frames["iFrame"].getElementsByTagName("a")[0].target="_blank";
h1 { text-align: center; font-size: 14px; color: #dd3d3d; font-family: Trajan Pro; width: 175px; } a { text-decoration: none; color: #ffffff !important; font-weight: bold; } a:hover { color: #ffffff !important; }
<script src="https://illiweb.com/rs3/30/frm/jquery/marquee/jquery.marquee.min.js"></script> <script src="http://code.jquery.com/jquery-1.4.2.min.js"></script> <div style="margin:-10px;"> <h1> Derniers messages </h1> <div style="margin-top: -10px; width: 175px; height: 80px; font-size: 10px; font-family: arial;" id="dernier_sjt"> <iframe id="iFrame" onload="var frame_sjt=window.frame_sjt.document.getElementById('comments_scroll_div');console.log(frame_sjt);document.getElementById('dernier_sjt').innerHTML=frame_sjt.innerHTML;$('.marquee').marquee();" src="http://www.endrothroad.net/h7-page-d-accueil/portal.forum" name="frame_sjt"></iframe> </div> </div>
不幸的是,除非iFrame所在的網頁與iFrame的目標位於同一域中,否則您就不能這樣做。
iFrame是網頁中顯示其他網站或文件的孔或窗口。 他們沒有連接到具有iFrame
的頁面。
現在,如果它在同一個域中,則可以訪問要更改的DOM。
EX:
$('iFrame').load( function() {
$('iframe').contents().find("head")
.append($("<style type='text/css'> a:hover { color: blue;} </style>"));
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.