2

I'm just trying to set a button to redirect to home page, but the page is just refreshing and not redirecting to the home page.

<script type="text/javascript">
    function backs(){
        location.replace("index.php");  
    }
</script>
JKD
  • 1,279
  • 1
  • 6
  • 26
Govi-Boy
  • 89
  • 10

3 Answers3

1

Use location.href instead:

<script type="text/javascript">
    function backs(){
        location.href = "index.php";  
    }
</script>
Always Helping
  • 14,316
  • 4
  • 13
  • 29
tom
  • 9,550
  • 6
  • 30
  • 49
  • 1
    Is it a Javascript error? It can break your whole JS. Maybe you have to fix this first. – tom Sep 08 '20 at 07:51
  • Test your function call: write `conosle.log(0)` into `backs()`. You should see a 0 in the console when klick the button. Do you? – tom Sep 08 '20 at 08:00
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/221137/discussion-between-govi-boy-and-kmgt). – Govi-Boy Sep 08 '20 at 08:05
1

in your button add the onClick event as following :

<button onClick="javascript:window.location.href='index.php">Edit</button>
Asmoun
  • 1,417
  • 5
  • 20
  • 53
0

Can you share the button code? Both the HTML and JS? I'm curious how you are calling the backs() function.

Also, as others suggested, location.href would be more appropriate.

Matt Budz
  • 193
  • 1
  • 11