-4

How can i make redirect without clicking.

i want to do it automatically

<script>
    $("#Div3").click(function(){

    window.location.replace("http://your.next.page/");

});

</script>
mike kent
  • 13
  • 4
  • Do you know what `$("#Div3").click(function(){`…`});` does? – Sebastian Simon Oct 28 '21 at 14:38
  • 3
    If your goal is to send the user off to another page when they visit a specific page, an HTTP redirect may be more appropriate. Skips the resource use of loading up a page and its assets. – Joseph Oct 28 '21 at 14:38
  • Look at the documentation for `$(document).ready()` [here](https://learn.jquery.com/using-jquery-core/document-ready/). But Joseph is right, a HTTP redirect sounds more appropriate. – darkmnemic Oct 28 '21 at 14:39
  • Does this answer your question? [Redirect from an HTML page](https://stackoverflow.com/questions/5411538/redirect-from-an-html-page) – Jonathan Irwin Oct 28 '21 at 14:44

3 Answers3

1

If you want to redirect as soon as the page is loaded, you can use

$( document ).ready(function() {
    window.location.replace("http://your.next.page/");
});

or you can use window.location.href to simulate a mouse click, whereas .replace simulates a HTTP redirect from the server, if that matters to you.

Dan P
  • 786
  • 7
  • 18
1

you can add in the header :

<head>
  <meta http-equiv = "refresh" content = "3; url = http://your.next.page/" />
</head>

source

Tim
  • 24
  • 6
0

You can use window.location.replace("http://your.next.page/"); directly so that the page is reloaded as soon as the javascript code is read.