1
http://xxxx.us/a/6126/securitycheckzpsfc10cc9.jpg#id=558554

我想在哈希后获取 URL 参数。

$hash = $_GET['hash'];

不工作

我想从地址栏中获取 URL。并获得哈希后的部分。

<?php
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; 
$url1 = parse_url($url);
echo $url1['fragment'];
?>

这也行不通。

4

2 回答 2

1

使用 javascript location.hash,您可以将哈希更改为GET参数并将其发送到您的 PHP 脚本

<!DOCTYPE HTML>
<html>
<head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
</head>
<body>
<a href="http://example.com/?some_parameter=x" class="hashed_link">Link</a>

<script>
    $().ready(function(){
        // navigate to in page anchor for testing
        window.location.href="#hash=12345678";

        // bind anchor click event
        $('.hashed_link').click(function(e){
            e.preventDefault();
            hash_anchor = $(this).attr('href')+'&'+location.hash.substr(1);

            alert(hash_anchor);
            //window.location.href=$(this).attr('href')+location.hash;
        });
    });
</script>
</body>
</html>
于 2013-06-21T19:27:24.113 回答
0

The hash isn't passed to the server, it is client-side only.

What you are trying to do is not possible, however, it would be possible to get the full URL via Javascript.

You should look into better ways of doing what you want to do. Why don't you pass it as a GET value instead?

于 2013-06-21T19:16:17.227 回答