所以我希望使用#hash链接..
由于我无法操纵历史链接,如果不支持HTML5,我希望将#photoid = 12345添加到链接(示例)。
现在我如何检查PHP中是否有#photoid?我通常不能做到
如果(isset($ _ GET [ “PHOTOID”])))
那么我该怎么做才能检测#photoid中的任何内容?
答案 0 :(得分:4)
你做不到。片段标识符完全在客户端上处理,永远不会发送到服务器,因此PHP无法读取它。
答案 1 :(得分:2)
你需要JavaScript:
var hash = window.location.hash;
alert(hash);
编辑:然后您可以调用php脚本并使用此信息。 jQuery中的示例:
$.post('do_something.php', {
// send the parameter 'hash'
hash: hash
}, function(result) {
// do something with the result
// e.g. add it to a div with an id "photos":
$('#photos').html(result);
});
“do_something.php”可能如下所示:
$hash = $_POST['hash'];
// do something, e.g. retrieve a photo based on the posted hash and echo it
// this will be in the result variable that's retrieved via Javascript
echo '<img src="photo_from_hash.jpg" alt="" />';