[英]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.如何将我的 Window.Location 按钮设置为同一页面,而无需在单击该按钮后无限重新加载它,以便我可以继续浏览将项目添加到我的购物车。 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.您可以使用window.location
将其重定向到您需要提供的同一页面,您必须确定提供的 url。
<a href='#' onclick="callfunction();" title='close'>button</a>
And the JS file
you can have it like this.而JS file
你可以这样。
function callfunction()
{
window.location= 'your-page.php';
}
The basic difference between the window.location
and window.location.href
is window.location
和window.location.href
的基本区别是
window.location
- This will add the location to the current page that you are browsing or looking for. window.location
- 这会将位置添加到您正在浏览或查找的当前页面。
window.location.href
- This will reload the page that you are giving in the URL over here. window.location.href
- 这将重新加载您在此处提供的 URL 中的页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.