Online computer courses, code, programming tutorial and sidebar information for monitoring Canadian S&P/TSX index. Build friendship and networking. Welcome to visit my blogs often!!! I also have two other sites: YouTube Channel and Google site.
Adsense
Popular Posts
- PHPWind-- A PHP forum script applcaition in China
- Free host forum is not reliable
- Formatting my post
- Powerful js library datable to export table in pdf, excel, sorting, freezing column and table header fixed (sticky)
- job interview questions (1)
- Set up a child account and set screen time limit in Windows 8
- PHP: add a download as pdf file button in report page
- phpexcel toggle expand and hide column in EXCEL and summary
- WinMerge - file and folder differencing and merging tool for Windows
- PHP connect IBM db2 database in XAMPP
Tuesday, January 28, 2014
PHP and JavaScript, redirect url with alert message or confirm
In PHP, when we use header to redirect to a new url, we may find the alert message disappear. The following code will not show alert message:
<script>
alert("User csv data is imported into publications database");
</script>
<?php
header("Location: index.php");
?>
To solve this,
method 1:
we can use:
<?php
$message = "User csv data is imported into publications database";
header("Location: index.php?message=" . urlencode($message));
?>
in index.php, add
if (isset($_GET['message'])) { echo $_GET['message']; }
method 2: only using JavaScript
<script>
alert("User csv data is imported into publications database");
window.location.href ="../index.php"
</script>
method 3: JavaScript with confirm yes or no
<script>
if(confirm('Are you sure you want to redirect homepage?')) {location.href='index.php'};
</script>
Another Javscript redirection example, redirect to different websites via choose the option list
<select onchange="if(this.value!='') location.href='index.php?userid='+this.value">
<option value=""> --- Choose a person --- </option>
<option value="1"> Jiansen </option>
<option value="2"> Tom </option>
<option value="3"> Jerry </option>
</select>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment