开发者

redirect displays alert box

开发者 https://www.devze.com 2023-03-20 04:43 出处:网络
a page directs users back to a page automatically <meta http-equiv=\"refresh\" content=\"1; URL=http://localhost/mywebsite/Untitled9.ph开发者_Go百科p\">

a page directs users back to a page automatically

<meta http-equiv="refresh" content="1; URL=http://localhost/mywebsite/Untitled9.ph开发者_Go百科p">

when it reaches 'Untitled9.php' i want it to display an alert box saying 'Message sucessfully posted'

I only want it to display when it id directed back to the page and not when first load

e.g Home - Message page = No alert

Home - message page - submit - redirect to message page = alert 'post sucessfully posted'


Can't control the DOM of a page externally.

What you could do however is pass a variable in the query string to the page you're redirecting to like this

Untitled9.php?message=success

Then on your new page have

<?php 
session_start();
if ($_GET['message'] == "success" && $_SESSION['revisit'] == "0")
{
    $_SESSION['revisit'] = "1";
    ?>
    <script type="text/javascript">window.alert('Message successfully posted.');</script>
    <?php
}
?>

In your first page change your code to look like this

<?php
session_start();
$_SESSION['revisit'] = "0";
?>
<meta http-equiv="refresh" content="1; URL=http://localhost/mywebsite/Untitled9.php">


If I understand your question correctly, this should work for you (assuming you alter the keys for the $_POST variables accordingly, of course):

<?php (isset($_POST['my_sub_btn'])): ?>
<script type="text/javascript">window.alert('Message successfully posted.');</script>
<?php endif ?>

Assuming you're submitting the message from a form, there should be no reason to redirect using a HTML redirect. Set the action attribute of your form to Untitled9.php and it will handle the rest...


Given your requirements, why not set a parameter on succes? Such as:

<meta http-equiv="refresh" content="1; URL=http://localhost/mywebsite/Untitled9.php?success=1">
0

精彩评论

暂无评论...
验证码 换一张
取 消