简体   繁体   English

页面重新加载不会在Greasemonkey-Script中停止。 怎么了?

[英]Page reload don't stop in Greasemonkey-Script. What's wrong?

I wrote a script in Greasemonkey to check if a button exists and then click it. 我在Greasemonkey中编写了一个脚本,以检查按钮是否存在,然后单击它。 Else to reload the page. 否则重新加载页面。

Problem: The Button is found and clicked correctly. 问题:找到并正确单击了按钮。 The page should not reload anymore but keeps on reloading and reloading. 该页面不应再重新加载,而是继续重新加载和重新加载。

What could be wrong???? 有什么问题吗????

Here is the code of my script: 这是我的脚本代码:

 (function() { 'use strict'; var zeilen = document.getElementsByClassName('content-card-entry fcb-row fcb-clear'); for (var i = 0; i < zeilen.length; i++) { var zeile = zeilen[i]; // Zeile mit Block if (zeile.children[0].children[0].innerHTML == "247") { //Den String der ID auslesen var IDString = zeile.children[0].children[0].id; //Den Identifikationsstring ctlxxx auslesen var ClickID = IDString.substr(42, 5); //Den ClickString zusammenbauen var anfang = "ctl00_ContentMiddle_TicketList1_GridView1_"; var ende = "_LinkButton1"; var clickstring = anfang+ClickID+ende; //Den Button suchen var element = document.getElementById(clickstring); //Wenn der Button vorhanden ist klicken und mir eine Nachricht senden element.click(); } else { location.reload(); } } })(); 

You loop over a set of elements, and do "click or reload the page" for each of them. 您遍历一组元素,并对每个元素进行“单击或重新加载页面”。 That means unless every single one of those elements is the button you're looking for, you're gonna reload the page. 这意味着除非这些元素中的每一个都是您要查找的按钮,否则您将重新加载页面。

Put a return after element.click() , so that your entire function exits if the button is found, and put location.reload() after the for loop, so that it is only called if the for loop terminated without returning from the function. element.click()之后放置一个return ,以便在找到按钮后退出整个函数,并将location.reload()放置在for循环之后,以便仅在for循环终止而未从函数返回时调用它。

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

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