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

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


锚是 #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>

索引.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";

    }

}


慕森王
浏览 216回答 1
1回答

凤凰求蛊

我通过window.location.reload()在它之后调用解决了它
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript