使用JavaScript更改将页面添加为书签时使用的URL [英] Using JavaScript to change the URL used when a page is bookmarked

查看:116
本文介绍了使用JavaScript更改将页面添加为书签时使用的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaScript 不允许您在不触发重新加载的情况下更新window.location.尽管我原则上同意此政策(应该无法访问我的网站并使JavaScript更改位置栏以读取www.yourbankingsite.com,但是)我相信应该可以将www.foo.org/index更改为www.foo.org/help.

JavaScript doesn't allow you to update window.location without triggering a reload. While I agree with this policy in principle (it shouldn't be possible to visit my website and have JavaScript change the location bar to read www.yourbankingsite.com,) I believe that it should be possible to change www.foo.org/index to www.foo.org/help.

我唯一关心的原因是添加书签.我正在使用照片浏览器,当用户预览特定图像时,如果他们应该将该页面作为书签,则希望该图像成为默认图像.例如,如果他们正在查看foo.org/preview/images0-30并单击图像#15,则该图像将扩展为中等大小的视图.如果他们随后将页面添加为书签,则我希望书签URL为foo.org/preview/images0-30/active15.

The only reason I care about this is for bookmarking. I'm working on a photo browser, and when a user is previewing a particular image, I want that image to be the default if they should bookmark that page. For example, if they are viewing foo.org/preview/images0-30 and they click on image #15, that image is expanded to a medium-sized view. If they then bookmark the page, I want the bookmark URL to be foo.org/preview/images0-30/active15.

任何想法,还是对此有安全障碍?我当然可以理解在这里应用的同一政策,但是可以梦想.

Any thoughts, or is there a security barrier on this one as well? I can certainly understand the same policy being applied here, but one can dream.

推荐答案

听起来像您应该查看的真正简单的历史.这就是Google(例如Gmail)允许任何页面添加书签(并具有历史记录)但不刷新整个页面的方式.

Sounds like you should check out Really Simple History. It's how Google (for example, Gmail) allows any page to be bookmarkable (and has history) but doesn't refresh the whole page.

对于其他方面(让人们访问您的网站,然后自动弹出正确的图片),我会尝试在页面加载和触发事件后检查 window.location.hash

As for the other side of things (having people visit your site then automatically popping up the correct image), I'd try checking window.location.hash once the page loads and firing events based on that.

这篇关于使用JavaScript更改将页面添加为书签时使用的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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