YOURLS 使用 Javascript 重定向

发布于 2024-08-22 13:45:22 字数 1112 浏览 3 评论 0原文

目前我正在使用 YOURLS PHP URL 缩短脚本。

在他们的functions.php中,似乎他们支持使用PHP标头位置和javascript的重定向。

Functions.php

我想要使用 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.

Functions.php

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迟月 2024-08-29 13:45:22

该功能已准备就绪。 javascript 重定向将在客户端发生,因此该脚本输出适当的 javascript。像这样调用它:

<?php # http://www.myurl.com/was/here.php

yourls_redirect_javascript('http://www.myurl.com/go/here.php');

?>

当此页面加载时,将使用 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:

<?php # http://www.myurl.com/was/here.php

yourls_redirect_javascript('http://www.myurl.com/go/here.php');

?>

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文