YOURLS 使用 Javascript 重定向
目前我正在使用 YOURLS PHP URL 缩短脚本。
在他们的functions.php中,似乎他们支持使用PHP标头位置和javascript的重定向。
我想要使用 javascript 进行重定向,这会在重定向之前向我显示消息。我在functions.php 中找到了这段代码
// Redirect to another page using Javascript. Set optional (bool)$dontwait to false to force manual redirection (make sure a message has been read by user)
function yourls_redirect_javascript( $location, $dontwait = true ) {
if( $dontwait ) {
echo <<<REDIR
<script type="text/javascript">
window.location="$location";
</script>
<small>(if you are not redirected after 10 seconds, please <a href="$location">click here</a>)</small>
REDIR;
} else {
echo <<<MANUAL
<p>Please <a href="$location">click here</a></p>
MANUAL;
}
}
,但我不知道该怎么做。该编码当前是否已注释或?我应该改变什么来使用 javascript 进行重定向?
请帮帮我。谢谢。
Currently I am using YOURLS PHP URL shorterning script.
In their functions.php, seems like they support both redirection which is with PHP header location and javascript.
I want to redirect with javascript, which will show me the message before redirect. I found this coding inside functions.php
// Redirect to another page using Javascript. Set optional (bool)$dontwait to false to force manual redirection (make sure a message has been read by user)
function yourls_redirect_javascript( $location, $dontwait = true ) {
if( $dontwait ) {
echo <<<REDIR
<script type="text/javascript">
window.location="$location";
</script>
<small>(if you are not redirected after 10 seconds, please <a href="$location">click here</a>)</small>
REDIR;
} else {
echo <<<MANUAL
<p>Please <a href="$location">click here</a></p>
MANUAL;
}
}
But I don't know how to do it. Is that coding currently commented or ? What should i change to redirect with javascript ?
Please help me out. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该功能已准备就绪。 javascript 重定向将在客户端发生,因此该脚本输出适当的 javascript。像这样调用它:
当此页面加载时,将使用 javascript 来重定向用户。如果 JavaScript 失败,将会有一个链接供他们点击以遵循重定向。
我怀疑“此处文档”语法让您有点困惑。阅读 PHP 文档以了解有关
echo <<<
的更多信息http://php.net/manual/en/function.echo.php
The function is all ready to go. A javascript redirect will occur on the client side, so this script outputs the appropriate javascript. Call it like so:
When this page loads javascript will be used to redirect the user. If the javascript fails, there will be a link for them to click to follow the redirect.
I suspect that the "here document" syntax is throwing you off a bit. Read the PHP Docs to learn more about
echo <<<
http://php.net/manual/en/function.echo.php