我在其中一個頁面上附加了Google News Box。Google新聞專欄,在新窗口中打開新聞頁面/標籤
現在,如果訪問者點擊新聞,他們將離開我的網站並前往新聞網站。
我想知道是否有可能在某處插入target="_blank"
,以便將新聞加載到新窗口/選項卡中。
注意:該鏈接位於谷歌的iframe中。所以我在想如果我能以某種方式在google iframe的頂部創建點擊事件,同時抓住它的url。
<iframe frameborder=0 marginwidth=0 marginheight=0 border=0
style="border:0;margin:0;width:928px;height:100px;"
src="http://www.google.com/uds/modules/elements/newsshow/iframe.html?
rsz=large&format=728x90&q=Internet%20Retailng%20Aus&element=true" scrolling="no"
allowtransparency="true"></iframe>
解決方案:
1:請參閱alfro的答案。
2:下面的代碼使用api
google.load("elements", "1", {packages : ["newsshow"]});
function onLoad() {
var options = {
"linkTarget" : "_blank"
}
var content = document.getElementById('news');
var newsShow = new google.elements.NewsShow(content,options);
}
你介意提供了一個例子來做到這一點通過API的方式,而不是到我使用的iframe(編輯問題) – Will
在另一個iframe中調用谷歌iframe。像谷歌那樣。 –
非常感謝您的代碼。我結束了與apis(編輯問題),因爲它有一些額外的功能,我正在尋找,但你的答案几乎一樣。 – Will