0

我需要获取页面中的所有链接,我确实得到了它们,问题是网站中存在两次 href,为了没有两次获取链接,我对变量做了一个小技巧:

getAlllinks: function()
{
    var links = content.document.getElementsByTagName("a");

    var entries = new Array;
    var liens = new Array;

    for(var i = 0; i<links.length; i++)
    {
        if(entries.indexOf(links[i].href) == -1)
        {
            entries.push(links[i].href);
            liens.push(links[i]);
        }
    }


    return links;
}

好的,到目前为止一切都很好,我将链接放在树(Xul)中,但我的问题从这里开始,我scrollIntoView用来滚动到链接

var tree = document.getElementById("Tree_links");
var tbo = tree.boxObject;
var row = { }, col = { }, child = { };
tbo.getCellAt(event.clientX, event.clientY, row, col, child);
var cellText = tree.view.getCellText(row.value, col.value);

var links = new Array;
links = cleanLinks();

for (var i = 0; i < links.length; i++) 
{
    if (links[i].href === cellText.toString()) 
    {
        links[i].scrollIntoView("true");
        if(links[i].style.backgroundColor == "rgb(255, 255, 0)")
        {
            links[i].style.backgroundColor='transparent';
        }
        else
        {
            links[i].style.backgroundColor='#ffff00';
        }
    }
}

它不会滚动页面中两次的链接,但是如果我将所有链接(两次或单个)放在树中它会滚动。

提前致谢。

4

1 回答 1

0

Well I figured it out, the trick i was doing with the variables i did it when filling the tree

于 2013-06-24T13:32:57.337 回答