javascript - 如何仅在第一次时按标题重新加载页面

标签 javascript php jquery html

我需要在第一次页面加载时立即重新加载或刷新页面(index.php)。因为 google.com 提供的是我的页面的 url,其中没有更多数据,例如 index.php?id=10。因此,我只需要在第一次时将 url 恢复为 index.php。我需要简单的解决方案。请帮忙吗?

最佳答案

我建议您使用 $_SESSION 全局数组,因为它允许您轻松地将信息从一个页面传递到另一个页面(或同一页面,如本例)。不过,请确保在使用它的每个页面上初始化 session 。

代码应该是这样的:

session_start();    //Important! Without this, $_SESSION doesn't work

//reload_index is a variable I'm using in the array, nothing restricted; you can use whichever name you like
if (!isset($_SESSION['reload_index']) || ($_SESSION['reload_index'] == 'yes'))
{
    $_SESSION['reload_index'] = 'no';
    header("Location: index.php");    //Or whatever page you want to go; you can add parameters as well, like index.php?id=10
}

//...Rest of the page

希望这能帮助您解决问题。谨致问候。

关于javascript - 如何仅在第一次时按标题重新加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35370350/

相关文章:

javascript - Ionic(单击)在 AlertController 消息属性中不起作用

javascript - 我可以在 html5 通知中显示 Font Awesome 图标吗

javascript - 单击按钮后无法 console.log ("xyz")。

php - 在 Woocommerce 中将 COD 默认订单状态更改为 "On Hold"而不是 "Processing"

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

javascript - 每当其 div 父容器类更改时运行 jquery 函数

javascript - 将数据从一个域的父窗口传递到另一个域的子窗口

php - 关于使用 phpmyadmin 在 mysql 中创建关系的建议

javascript - jQuery .validate 规则似乎不适用? (jsfiddle)

jquery - 如何操作变换: translate3d values with jQuery?