简体   繁体   中英

Page just reloads but doesn't redirect to the page

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>

Use location.href instead:

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

在您的按钮中添加onClick事件如下:

<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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM