gpt4 book ai didi

php - 打开模态窗口 "using"PHP

转载 作者:可可西里 更新时间:2023-11-01 01:04:21 29 4
gpt4 key购买 nike

我正在用 PHP 创建一个登录系统,并试图让它变得更好一些。

当您注销时,您将被重定向回 index.php。像这样:

header("loaction: index.php?logout=true")

这使得 url 看起来像 www.mysite.com/index.php?logout=true。然后我使用以下代码:

if(isset($_GET['logout'])) {

$logoutvalue = $_GET['logout'];

if($logoutvalue = "true") {
$notification = "You've been logged out!";
}

从 URL 中获取注销的值并用它做一些事情。

我有一个小的弹出窗口,它将显示通知变量的值。在这种情况下,它是“你已经注销了!”我的问题是如何在页面加载时以及 url 等于/index.php?logout=true 时显示模态窗口?

非常感谢所有评论、回答和建议!

谢谢!- 瑞安

最佳答案

首先,

您不能直接“使用 PHP 打开模态窗口”。您只能通过交换变量(通过 JSON 或 XML)或将 PHP 条件直接嵌入到您的标记中来做到这一点。

PHP 和 JavaScript 是独立的。

My question is how do I get the modal window to display when the page loads and when the url equals /index.php?logout=true ?

您可以通过两种方式实现这一目标。
第一:充分利用将 PHP 条件直接嵌入到标记中。

第二:在某处隐藏输入,例如 ( <input type="hidden" id="showModal" /> ),然后通过 JavaScript 本身检查它是否存在。

例如:

<!DOCTYPE html>
<html>
<head>

<script type="text/javascript">

window.onload = function(){

if ( document.getElementById('showModal') ){

alert('Box'); //replace with your own handler
}

}

</script>

</head>
<body>

<?php if ( isset($_GET['logout']) && $_GET['logout'] === 'true' ): ?>

<input type="hidden" id="showModal" />

<?php endif;?>
</body>
</html>

关于php - 打开模态窗口 "using"PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14639235/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com