Page just reloads but doesn't redirect to the page

Viewed 141

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>
3 Answers

Use location.href instead:

<script type="text/javascript">
    function backs(){
        location.href = "index.php";  
    }
</script>

in your button add the onClick event as following :

<button onClick="javascript:window.location.href='index.php">Edit</button>

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.

Related