每隔几分钟检查当前位置并单击链接按钮

时间:2011-06-15 18:44:56

标签: html xpath location greasemonkey

我在拍卖网站上得到了这种情况。 trada.net有时他们会离线几个小时,当前的地址如:offline location,现在,它基本上禁用了我的所有其他GM脚本,因为没有数据可以分析,这是错误的地点。现在,我如何通过一个脚本来检查当前位置是否为“离线”位置,然后如果为true,则单击名为“Live Auctions”的站点上的按钮,xpath为:{{1每5分钟,或任何时间框架。我要执行的时间范围部分,但链接或按钮的查找仍然存在问题,然后找到我当前的loaction是我的另一个障碍。

谢谢

1 个答案:

答案 0 :(得分:0)

这样的事情应该这样做,假设脚本为http://www.trada.net/*触发。 :

//--- Is this the offline page?
if (/errorPage/i.test (window.location.href) )
{
    //--- Wait 5 minutes and try the main page again.
    var timeDelay       = 5 * 60 * 1000;    //-- 5 min, in milliseconds.

    setTimeout (function() {

        //--- Get "button" target.  Nominally, http://www.trada.net/p_home.aspx
        var desiredPage = $('div#art-main div.art-nav ul.art-menu span li a.active')[0].href;

        window.location.replace (desiredPage);

    }, timeDelay);

    return; //-- Don't process the rest of the script since we are not yet on target page(s).
}


请注意,您可以跳过desiredPage部分,然后使用:

window.location.replace ('http://www.trada.net/p_home.aspx');