是否可以在iframe中更改或附加超鏈接?IFrame中的HREF鏈接改變href值
這裏是我的代碼:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript">
function changelinks(iframe){
var as = iframe.contentDocument.getElementsByTagName('a');
for(i=0;i<as.length;i++){
as[i].setAttribute('href',"http://www.yahoo.com");
}
}
</script>
</head>
<body>
<iframe src="http://www.google.com" onload="changelinks(this)"></iframe>
我的目標是當點擊下iframe中的任何鏈接,目標網址將是www.yahoo.com。
任何建議是值得歡迎的。 UPDATE我在iframe中找不到位於我的服務器中的網站。
這是因爲在iframe鏈接到雅虎的所有環節。 COM?如果是這樣,請參閱[這裏](http://stackoverflow.com/questions/1037839/how-to-force-link-from-iframe-to-be-opened-in-the-parent-window)。 – Wilf
你不需要'setAttribute',你不可以只用'as [i] .href ='http:// www.yahoo.com''? – Cilan
@Wilf我沒有發出父窗口或新的。 –