javascript - 在关闭当前页面的同时刷新旧页面并在 url 中添加一个 Action

标签 javascript php url

我试图在提交表单后关闭窗口并刷新主页,然后在 url 中传递信息以进行操作弹出。

我的代码工作正常,但似乎无法传递信息。

这是工作代码

echo "<script>window.close();window.opener.location.reload(true);</script>";

我已经尝试了以下方法,我知道这是错误的,但不确定在哪里寻找答案,因为不太确定要搜索什么

<?php
// include database connection
 $id=isset($_GET['id']) ? $_GET['id'] : die('ERROR: Record ID not found.');
// include database connection
include '../../../assets/connect.php';

try {

    // get record ID
    // isset() is a PHP function used to verify if a value is there or not

    // delete query
    $query = "DELETE FROM investment_return Where id = '$id'";
    $stmt = $con->prepare($query);
    $stmt->bindParam(1, $id);

    if($stmt->execute()){
        // redirect to read records page and 
        // tell the user record was deleted
            echo "<script>window.close();window.location.href = window.location.href + '?action=entered';</script>";
    }else{
        die('Unable to delete record.');
    }
}

// show error
catch(PDOException $exception){
    die('ERROR: ' . $exception->getMessage());
}
?> 

如您所知,我正在尝试将 ?action=entered 添加到 url 的末尾。

上面的代码关闭了窗口,但没有在最后添加所需的信息,现在不需要刷新,因为它将是一个新的 url 加载。

非常感谢

最佳答案

为此你可以使用这个

window.location.href = window.location.href + "?action=entered";

它改变了当前窗口的位置。
例如,如果您的页面是 https://www.google.com,它会将您重定向到 https://www.google.com?action=entered

处理您的请求添加

if (isset($_GET['action'] && $_GET['action'] == 'enabled') {
    //here add your code for example
    echo "<script>alert('deleted');</script>"
}

关于javascript - 在关闭当前页面的同时刷新旧页面并在 url 中添加一个 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40563744/

相关文章:

javascript - 检测 URL 更改(无窗口卸载)

javascript - 在 jquery 自动完成插件中显式调用自动完成函数

javascript - 我可以在 Mobile Safari 上用 user-css 覆盖 CSS 吗?

php - 在 URL 查询中表示约 200 个 bool 标志

PHP/GD : Better Gaussian blur

PHP Mysql 安全密码

apache - .htaccess RewriteRule 国家/地区代码和 url

javascript - cheeriojs - 如何遍历每个对象?

javascript - 在 Google 脚本中,如何获取列中每个单元格的月份?

php - 提交表单后下拉选项未保持选中状态