Home > Backend Development > PHP Problem > How to implement jump after prompt in PHP?

How to implement jump after prompt in PHP?

Guanhui
Release: 2023-03-01 16:32:01
Original
3408 people have browsed it

How to implement jump after prompt in PHP?

#PHP How to implement jump after prompt?

First create a PHP file and open it for editing;

Then use the function "echo()" in the PHP code to output the JS code;

Then in the JS Use the function "alert()" in the code to prompt the message;

Finally, point the "location.href" in JS to the jump link.

Code sample

function show_msg($msg, $url)
{
    echo "<script>alert(&#39;{$msg}&#39;);window.location.href=&#39;{$url}&#39;;</script>";
    exit();
}

show_msg(&#39;this is Message!&#39;, &#39;/user/show&#39;);
Copy after login

Advanced version

function message($msgTitle,$message,$jumpUrl){ 
    $str = &#39;<!DOCTYPE HTML>&#39;; 
    $str .= &#39;<html>&#39;; 
    $str .= &#39;<head>&#39;; 
    $str .= &#39;<meta charset="utf-8">&#39;; 
    $str .= &#39;<title>页面提示</title>&#39;; 
    $str .= &#39;<style type="text/css">&#39;; 
    $str .= &#39;*{margin:0; padding:0}a{color:#369; text-decoration:none;}a:hover{text-decoration:underline}body{height:100%; font:12px/18px Tahoma, Arial,  sans-serif; color:#424242; background:#fff}.message{width:450px; height:120px; margin:16% auto; border:1px solid #99b1c4; background:#ecf7fb}.message h3{height:28px; line-height:28px; background:#2c91c6; text-align:center; color:#fff; font-size:14px}.msg_txt{padding:10px; margin-top:8px}.msg_txt h4{line-height:26px; font-size:14px}.msg_txt h4.red{color:#f30}.msg_txt p{line-height:22px}&#39;; 
    $str .= &#39;</style>&#39;; 
    $str .= &#39;</head>&#39;; 
    $str .= &#39;<body>&#39;; 
    $str .= &#39;<div class="message">&#39;; 
    $str .= &#39;<h3>&#39;.$msgTitle.&#39;</h3>&#39;; 
    $str .= &#39;<div class="msg_txt">&#39;; 
    $str .= &#39;<h4 class="red">&#39;.$message.&#39;</h4>&#39;; 
    $str .= &#39;<p>系统将在 <span style="color:blue;font-weight:bold">3</span> 秒后自动跳转,如果不想等待,直接点击 <a href="{$jumpUrl}">这里</a> 跳转</p>&#39;; 
    $str .= "<script>setTimeout(&#39;location.replace(&#39;".$jumpUrl."&#39;)&#39;,2000)</script>"; 
    $str .= &#39;</div>&#39;; 
    $str .= &#39;</div>&#39;; 
    $str .= &#39;</body>&#39;; 
    $str .= &#39;</html>&#39;; 
    echo $str; 
}
Copy after login

Recommended tutorial: "PHP

The above is the detailed content of How to implement jump after prompt in PHP?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template