操作/更改地址栏链接

发布于 2024-10-12 17:38:25 字数 817 浏览 10 评论 0原文

我在经历这件事时已经脱离了自己的“想法”。

我有一个相册查看器。当您单击“下一步”时,我希望地址栏与其一起挂起,例如,如果您从“?photoid=1”开始,然后单击“下一步”(附加下一张图片和其他内容),然后我希望它显示“?photoid=2”。

现在我无法在不更改/操作的情况下说出 ?photoid=2 ,而如果没有 HTML5,您就无法做到这一点。

我用 HTML5 制作了一个运行良好的脚本,但是我需要照顾那些没有 HTML5 的人(只有 chrome、ff4 等支持 html5) 从此创建脚本( https://developer.mozilla.org/en/DOM/Manipulated_the_browser_history )

我想添加 #photoid=2 所以, ?photoid=1#photoid=2 然后检查 # 中是否有任何内容,然后使用它而不是 $_GET .. 但显然你不能这样做,因为 # 是客户端已处理但从未发送到服务器。

那我该怎么办呢?

有什么建议可以解决这个问题吗?我检查了facebook,他们对IE用户做了什么,我可以听到它“点击”(来自IE的烦人的点击声)两次..第一次是转到下一张图片,第二次点击声改变了地址栏?! (如何?)。

然后我还想嘿,html5只在ff4中支持,我得到了ff3.6,当你浏览相册照片时,他们操纵地址栏url,完全像我想要的那样(以及我写的目的,但它仅适用于 Chrome 和 ff4..?)。他们怎么能这么做呢?

I am out of my own "ideas" going through this.

I have a album viewer. When you click next I want the adressbar to hang with it, e.g if you start on ?photoid=1, and click next (next picture appends and stuff), and then i want it to say ?photoid=2.

Now I cant make it say ?photoid=2 without changing/manipulating, and this you cant do without HTML5.

I have made a script in HTML5 that works fine, but then I need to take care of those who dont have HTML5(only chrome, ff4 etc supports html5)
Made the script from this( https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history )

I thought of adding #photoid=2 so, ?photoid=1#photoid=2 and then check if theres anything in # then use that instead of the $_GET.. But apparently you cannot do that as # is client side handled and never sent to the server.

So what should I then do?

Any suggestions please to make a workaround this? I checked facebook, what they did to IE users, and I could hear that it "clicked" (the annoying click sound from IE) twice.. the first was to get to the next picture, the second click sound changed the adressbar?!(how?).

And then I also thought hey, html5 is only supported in ff4, and I got ff3.6, and they manipulate the adress bar url when you browse through the album photos, exactly like how I wanted (and what I have written for but it only works in Chrome and ff4..?). How could they do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

入画浅相思 2024-10-19 17:38:25

哈希是更改网址栏而不自动刷新您所在页面的唯一方法。这就是为什么它在历史上是一个锚标记(哈希)。其他一切都会告诉您的浏览器转到不同的页面。如果您不希望它转发,请输入一个哈希值,然后使用 javascript 读取该哈希值并按照您想要的方式执行操作。使用 jQuery 很容易,或者您可以深入了解 Asual 的 swf 地址 js 库jQuery 的哈希标签更改侦听器 插件。

The hash is the only way to change out the url bar without automatically refreshing the page you're on. That's why it's an anchor tag (the hash) historically. Everything else tells your browser to go to a different page. If you don't want it to forward, throw in a hash and then read that hash with javascript and do what you want that way. It's easy with jQuery, or you could dig into Asual's swf address js library or jQuery's Hash Tag Change Listener plugin if you want to use your browsers back/forward button to go through your history states.

鯉魚旗 2024-10-19 17:38:25

我不太确定你的理解是否正确,但这是我针对类似问题提出的建议。

为什么不通过编辑 location.hash 来设置 url,就像您所说的那样,使其看起来像这样:www.mydomain.com/photos/#photoid=2

现在,当有人调用此网址时,浏览器将尝试加载 www.mydomain.com/photos/ 并获取必要的标记,但不是照片,您现在可以做的是读取 location.hash (这将返回 photoid=2)并通过 AJAX 向服务器发送请求来加载图片,路径如“www.mydomain.com/photos/”+ location.hash

I'm not quite sure if understood your quite right, but here's what I came up with for a similar problem.

Why don't you just set the url by editing the location.hash just like you said to make it look something like this: www.mydomain.com/photos/#photoid=2.

Now when somebody calls this url the browser will try to load www.mydomain.com/photos/ and will get the necessary markup but not the photo and what you can do now is read the location.hash (which will return photoid=2) and load the picture via AJAX by sending a request to the server with a path like "www.mydomain.com/photos/" + location.hash

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文