开发者

Show a list of links in an iframe one at a time with jquery

Ok, so I need help with a script that takes a list of urls in an array, then shows each url one at a time in an iframe, and allows me to put a border around the link to the next item of the list INSIDE the iframe. I need it to show the page for about 3 seconds, then display the next page, and the next and so on, but only one page at a time.

Here's where I'm at so far:

    var links = ["link1", "link2", "link3"];

    for (var i = 0; i < links.length; i++)
    {
        $("#viewer iframe")
            .attr('src', "http://www.mysite.com/" + links[i])
            .load(function() {
                $(this).contents().f开发者_Go百科ind("a[href*='" + links[i+1] + "']").css("border", "1px solid black");});
        setTimeout('$("#viewer iframe").attr("src", "")', 3000);
    }

This works to show the first link in the array and then after 3 seconds sets the iframe src to nothing, but it doesn't show the subsequent links.


Try this:

var links = ["link1", "link2", "link3"];
var current = 0;

function showNextLink()
{
   if (current >= links.length) {
       return;
   }

   $("#viewer iframe")
        .attr('src', "http://www.mysite.com/" + links[current])
        .load(function() {
            if (current < links.length) {
                $(this).contents().find("a[href*='" + links[current+1] + "']").css("border", "1px solid black");}});

   current++;
   setTimeout(arguments.callee, 3000);
}

showNextLink();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜