使用#hash链接 [英] Working with #hash links

查看:154
本文介绍了使用#hash链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我希望使用#hash链接.

So I wish to work with #hash links..

由于我无法操纵历史记录链接,因此,如果不支持HTML5,我希望在该链接中添加#photoid = 12345(示例).

As I cannot manipulate the history links, if HTML5 isnt supported I wish to add #photoid=12345 to the link (example).

现在如何在#photoid中检查PHP?我不能正常做

Now how can i check in PHP if there is any in #photoid ? I cant do normally

if(isset($ _ GET ["photoid"])))

if(isset($_GET["photoid"])))

那么我应该在这里做什么以检测#photoid中的任何内容?

so what should i do here to detect where anything is in #photoid?

推荐答案

为此,您将需要JavaScript:

You'll need JavaScript for that:

var hash = window.location.hash;
alert(hash);

,然后可以调用php脚本并使用此信息. jQuery 中的示例:

you can then call on a php script and use this information. Example in 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"可能看起来像这样:

And "do_something.php" could look like this:

$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="" />';

这篇关于使用#hash链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆