我目前有下面的腳本來抓取div(scrollbox)中的鏈接,正如你看到的那樣設置爲在新窗口中打開鏈接。我需要讓它們在原始頁面內的div中打開。我可以用這個腳本來做到這一點嗎?如果不是我應該使用什麼?具有動態的(如更改/更新,例如,博客頁面)包含在一個div中的div包含在同一個div中
function Init()
{
// Grab the appropriate div
theDiv = document.getElementById('scrollbox');
// Grab all of the links inside the div
links = theDiv.getElementsByTagName('a');
// Loop through those links and attach the target attribute
for (var i=0, len=links.length; i < len; i++) {
// the _blank will make the link open in new window
links[i].setAttribute('target','_blank');
}
}
window.onload = Init;
非常感謝您的幫助!
你的意思是DIV內容應根據改變網頁的內容?如果是這樣,AJAX可能是合適的。 – pimvdb 2011-05-17 14:41:12
@pimvdb排序但不是真的。 DIV的內容會定期更新,但只有點擊鏈接後才能更改內容。因此我不能輸入鏈接並將其設置爲靜態目標。我必須使用上面的腳本'抓取'DIV中的任何鏈接,並設置這些鏈接的目標,這些鏈接當時可能是什麼。 – David 2011-05-17 15:04:51
感謝您的解釋。但如果我沒有錯,那麼目標不是一個窗口,而是一個DIV元素?因爲在這種情況下,你需要一些AJAX技術來加載數據而不刷新當前頁面(或使用'iframe')。 – pimvdb 2011-05-17 15:11:42