0

I would like to a HTML code with the following functions if you guys can help , please.

Once the page loads, after 1 second to auto click on a hyperlinked text , how do I do this ? For the new website to be opened in the same window.

I have this code but this one is sending me to a new window and the pop up is blocking - not good

<!DOCTYPE html>
<html>
<body>
<head>
<script>
function autoClick(){
document.getElementById('linkToClick').click();
}
</script>
</head>
<body onload="setTimeout('autoClick();',700);">
<a id="linkToClick" href="http://www.google.com" target="_blank">GOOGLE</a>
</body>


</body>
</html>

Thanks

Yserbius
  • 1,375
  • 12
  • 18

2 Answers2

0

Instead of using <a href=> you should try just setting the variable window.location.href. So your code should look something like this:

<body onload="window.location.href='http://www.google.com',700);">

https://www.w3schools.com/howto/howto_js_redirect_webpage.asp

Yserbius
  • 1,375
  • 12
  • 18
0

Let me preface this by saying this is extremely questionable when it comes to web design, and generally regarded as a shady or bad practice. That said:

$(window).on('load', function(){ window.location = 'http://example.com' });

OR (vanilla JS)

window.onload = function(){ window.location = 'http://example.com' };

Again, be careful with this. If you want to do something like this, you need a pretty good reason why.

Possible duplicates:

Redirect from an HTML page

HTML redirect on page load

jpegzilla
  • 80
  • 2
  • 10