我在通过 php 动态回显 javascript 时遇到了一些问题。这是我的代码
$url = "http://www.newsite.com";
echo "
<html>
<head>
<title>Redirecting</title>
</head>
<body onload='redirect()'>
Not Logged In
<script type = 'text/javascript'>
function redirect() {
window.location=".$url."
}
</script>
</body>
</html>
";
我的 javascript 控制台告诉我找不到“redirect()”(未捕获的 ReferenceError:未定义重定向)
知道是什么原因造成的吗?
最佳答案
完全放弃基于客户端的重定向。使用:
header("HTTP/1.0 302 Moved Temporarily");
header("Location: $url");
关于php - PHP 回显的 Javascript 不运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8360008/