繁体   English   中英

重定向到站点并跳转到锚点

[英]Redirect to site and jump to anchor

我尝试重定向到一个站点并跳转到该站点上的锚点。

锚点是#tab-5

我试过了:

window.location.href = "/property/details?id=123#tab-5";

window.location.replace("/property/details?id=123#tab-5");

我还尝试使用带有域名的完整 URL 。

但该网站不会重新加载。 URL 刚刚更换,并没有跳到锚点。


.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Send would-be 404 requests to Craft
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
    RewriteRule (.+) index.php?p=$1 [QSA,L]
</IfModule>

index.php

<?php
ob_start();
session_name("xxx");
session_start();

include("app/Routes.php");
$template = checkRoute();

// Redirect to login page if user is not logged in
if (!$template && !isset($_SESSION["logged_in"])) {

    $bodyClass = "login";
    $template = "templates/php/login.php";

// Redirect to start page (list view) if user is logged in and no url is given
} else if (!$template) {

    header("Location: /property/list");
    exit;
}

// Redirect to template
if (file_exists($template)) {
    require_once($_SERVER["DOCUMENT_ROOT"] . "/master.php");
    exit;
}

应用程序/Routes.php

<?php
/**
 * A .htaccess rule always calls the index.php if a file could not be found.
 * This method gets called by index.php and creates a path out of the request
 * url path and returns the affiliated template file if exist. If nothing is found,
 * then return "no-route" template.
 */
function checkRoute()
{
    $redirectUrl = (isset($_SERVER["REDIRECT_URL"])) ? $_SERVER["REDIRECT_URL"] : "";
    $_SERVER["REDIRECT_URL"] = "";

    if (!empty($redirectUrl) && $redirectUrl !== "/login") {

        $templateRoot = "templates";
        $template = $templateRoot . "/php". $redirectUrl .".php";

        if ( ! file_exists($template)) {

            $template = "/". $template;

            if ( ! file_exists($template)) {
                $template = $templateRoot . "/html/no-route.html";
            }
        }

        if (file_exists($template)) {
            return $template;
        }
    }

    if (!empty($_SESSION["logged_in"])) {
        return false;
    }
}

我通过在它之后调用window.location.reload()解决了它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM