简体   繁体   English

在页面上找到一个命名链接,然后单击它-用Javascript

[英]Find a named link on the page, then go click it - in Javascript

I'm using Greasekit, so needs this to be in Javascript, please 我正在使用Greasekit,因此需要使用Javascript

What I would tell a human to do 我会告诉人类要做的

Click the link called < Previous so that it opens in a new window (in the example below, it goes to Page 22, but it could be any number, so it really needs to look for this specific link) 单击名为< Previous的链接,以便在新窗口中打开(在下面的示例中,它转到第22页,但是它可以是任何数字,因此它确实需要查找此特定链接)

<table class="v_page_nav" border="0" cellpadding="5" cellspacing="0" width="100%">
    <tr>
        <td width="100%">Showing 551-575 of 610 Results</td>
        <td>
            <a href="/wine/newsletter?ie=UTF8&amp;page=22" id="pagination-prev-link">
                < Previous</a>| Page:</td>
        <td class="off">
<a href="/gp/vine/newsletter?ie=UTF8&amp;page=1" id="pagination-page-1">1</a>
        </td>
        <td>...</td>
        <td class="off">
<a href="/wine/newsletter?ie=UTF8&amp;page=22" id="pagination-page-22">22</a>
        </td>
        <td class="on">
<a href="/wine/newsletter?ie=UTF8&amp;page=23" id="pagination-page-23">23</a>
        </td>
        <td class="off">
<a href="/wine/newsletter?ie=UTF8&amp;page=24" id="pagination-page-24">24</a>
        </td>
        <td class="off">
<a href="/wine/newsletter?ie=UTF8&amp;page=25" id="pagination-page-25">25</a>
        </td>
        <td>| <a href="/wine/newsletter?ie=UTF8&amp;page=24" id="pagination-next-link">Next ></a>
        </td>
    </tr>
</table>

The code: 编码:

the last two lines of the answer are probably: 答案的最后两行可能是:

link.target="_blank";
link.click();

(this is to open the link in the new window) ..but what I want to know is how to write the rest of the code; (这是在新窗口中打开链接)..但是我想知道的是如何编写其余代码; the lines that go above it. 上方的线。

Note 注意

an alternative to finding < Previous might be to look for a link with the id pagination-prev-link 查找< Previous一个的替代方法可能是查找带有id pagination-prev-link

考虑您的最后一句话:

var link = document.getElementById('pagination-prev-link');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM