Question

window.setTimeout(function() {window.location = document.getElementById('redirect')[0].onclick;}, 2000);

Hi guys, what's wrong in this, please? All it should do is: activate an element with id="redirect" which's onclick is :to go back in history.

<a id="redirect" onclick="window.history.back()">Go back (auto after 2sec)</a>
Was it helpful?

Solution 2

To trigger the element click after 2 seconds you can do this:

window.setTimeout( function() {
    document.getElementById('redirect').click();
}, 2000);

<a id="redirect" onclick="window.history.back()">Go back (auto after 2sec)</a>

or you could do:

 window.setTimeout( function() {
    window.history.back()
}, 2000);

<a id="redirect" onclick="window.history.back()">Go back (auto after 2sec)</a>

OTHER TIPS

Window.Location cannot receive a "window.history.back()" value. You must do that:

<a id="redirect" onclick="javascript:window.setTimeout(function() window.history.back(), 2000);">Go back (auto after 2sec)</a>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top