javascript PHP : 如何在 header('location:http://domain.com'); 之前使用 alert();

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15099924/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 23:29:36  来源:igfitidea点击:

PHP : How to use alert() before header('location:http://domain.com');

phpjavascript

提问by Mohammad Alipour

How to use alert()before header('location:http://domain.com');so that alert work. the problem is that php code is powerful and ignore alert()

alert()之前如何使用,header('location:http://domain.com');以便警报工作。问题是 php 代码很强大,忽略了 alert()

回答by user1477388

I think you are trying to do this?

我认为你正在尝试这样做?

alert('After this goes away, I will be redirected via JavaScript');
window.location = "http://domain.com";

Ref. How do I redirect with Javascript?

参考 如何使用 Javascript 重定向?

回答by Benny

To use Javascript like alert() you have to have a loaded web page. You can do the header() function then within the next request that is probably called after the alert.

要使用像 alert() 这样的 Javascript,你必须有一个加载的网页。您可以在下一个可能在警报之后调用的请求中执行 header() 函数。