简体   繁体   中英

redirect displays alert box

a page directs users back to a page automatically

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

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
eg Home - Message page = No alert
Home - message page - submit - redirect to message page = alert 'post sucessfully posted'

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">

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">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM