0

I have a link called

www.example.com/previewAndAccept.php 

but when I click the link, sometimes it redirects to:

www.example.com/NoMoreHits.php 

Since it redirects I can't use the google chrome auto refresh script to refresh the URL, since it would be refreshing the second link instead of the first. My question is, is there a way to write a script to repeatedly check the original link every second?

2 Answers 2

1

Well, supposedly TamperMonkey has access to the window.location object, so you could set window.location.href directly to the desired URL instead of just using window.location.reload().

In your example something like this could work:

setInterval( () => window.location.href = 'http://www.example.com/previewAndAccept.php', delayInMilliseconds ) 

ps.: Simply window.location = 'http://www.example.com/previewAndAccept.php' should work as well. Make sure to specify the protocol (http or https), otherwise the browser might just append the text to the end of the current path instead of replacing it.

Sign up to request clarification or add additional context in comments.

2 Comments

But if the @match is www.example.com/previewAndAccept.php, it'll just stop once it gets to www.example.com/NoMoreHits.php and stop refreshing, won't it?
Well, does adding www.example.com/NoMoreHits.php as a match have undesirable side effects? If not, then that could be a solution to this problem.
0

Try this :

window.setInterval(function(){ var a = document.getElementById('linkId'); if (a) { a.setAttribute('href', 'www.example.com/previewAndAccept.php'); } }, 1000);
<a href="www.example.com/previewAndAccept.php" title="this link" id="linkId"> Link </a>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.