我试图在提交表单后关闭窗口并刷新主页,然后在 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/