简体   繁体   中英

Window.Location to the same page PHP

I have a button which puts an item to my cart. How can I set my Window.Location button to the same page without Reloading it infinitely after click the button so I can continue browsing adding items to my cart. Here is my code.

 echo '<script>window.location.reload()</script>';

The above codes keeps reloading. I just need the item to add the cart and continue browsing.

<a href='#' onclick='callfunction(); window.location="thispage.php";' title='close'>button</a>

但是既然它来自 PHP,为什么不使用 header 呢?

header('refresh:10;thispage.php');

You can use window.location in order to redirect it to the same page that you need provide you must be sure with the url that give.

<a href='#' onclick="callfunction();" title='close'>button</a>

And the JS file you can have it like this.

function callfunction()
{
   window.location= 'your-page.php';
}

The basic difference between the window.location and window.location.href is

window.location - This will add the location to the current page that you are browsing or looking for.

window.location.href - This will reload the page that you are giving in the URL over here.

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